How to Create Custom Email Templates for Easy Digital Downloads

Home » Snippets » How to Create Custom Email Templates for Easy Digital Downloads
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you a user of Easy Digital Downloads (EDD) plugin for WordPress? Do you want to have more control over the design and layout of the emails that are sent to your customers? In this article, we will show you how to create custom email templates for Easy Digital Downloads, allowing you to personalize the emails and enhance the branding of your online store. Whether you want to add your logo, change the colors, or include additional information, custom email templates will give you the flexibility to tailor the emails to match your unique brand identity. Let’s dive in and learn how to create stunning, professional-looking email templates for Easy Digital Downloads.

					function wpturbo_custom_email_template($template, $template_name, $args) {
    if ($template_name === 'edd_purchase_receipt') {
        $template = get_stylesheet_directory() . '/edd-templates/purchase-receipt.php';
    } elseif ($template_name === 'edd_purchase_receipt_html') {
        $template = get_stylesheet_directory() . '/edd-templates/purchase-receipt-html.php';
    }
    return $template;
}
add_filter('edd_get_template_part', 'wpturbo_custom_email_template', 10, 3);
				

In this section, we will discuss how to create custom email templates for Easy Digital Downloads using WordPress.

The code snippet provided defines a function called wpturbo_custom_email_template that is responsible for overriding the default email templates for the purchase receipt. This function takes three parameters: $template, $template_name, and $args.

The first part of the code checks if the $template_name is equal to 'edd_purchase_receipt'. If it is, it sets the $template variable to the path of a custom email template file named 'purchase-receipt.php', located in the 'edd-templates' folder inside the active theme’s directory.

if ($template_name === 'edd_purchase_receipt') {
    $template = get_stylesheet_directory() . '/edd-templates/purchase-receipt.php';
}

The second conditional statement checks if the $template_name is equal to 'edd_purchase_receipt_html'. If it is, it sets the $template variable to the path of a custom email template file named 'purchase-receipt-html.php', also located in the 'edd-templates' folder inside the active theme’s directory.

elseif ($template_name === 'edd_purchase_receipt_html') {
    $template = get_stylesheet_directory() . '/edd-templates/purchase-receipt-html.php';
}

By using these conditional statements, we are able to customize both the plain text and HTML versions of the purchase receipt email template.

Finally, the function returns the $template variable, which now contains the path of the custom email template file. This ensures that the custom template will be loaded instead of the default template.

return $template;

To activate this custom email template, we need to hook the wpturbo_custom_email_template function to the edd_get_template_part filter using the add_filter function. The edd_get_template_part filter is triggered when Easy Digital Downloads tries to locate a template part, and we can use it to override the default email template.

add_filter('edd_get_template_part', 'wpturbo_custom_email_template', 10, 3);

By following these steps, you can easily create and use your own custom email templates for Easy Digital Downloads in WordPress.

Register an account to save your snippets or go Pro to get more features.