How to customize PrestaShop Email Templates

In this tutorial you are going to learn how to customize the default email templates that are used to notify new customers and how to use alternative templates for new affiliates, using the Affiliates Pro for PrestaShop module.

We will assume that your PrestaShop installation folder is called prestashop. Where exactly it is located depends on your server environment. For example, it could be /var/www/prestashop or ~/public_html/prestashop – if you are unsure where your PrestaShop files are located, please ask your web administrator or your hosting provider.

The default Email Templates

PrestaShop mails folderPrestaShop’s email templates are found in prestashop/mails. For each language, you will find a subfolder with the email templates. For example, prestashop/mails/de for German email templates, prestashop/mails/en for the templates in English etc.

For each template, you will find two versions, one HTML and another plain text version. We will be customizing the notification email that is sent to new customers below. The relevant files are account.html and account.txt, holding respectively the HTML and the plain text versions of the notification sent to new customers.

You can customize these using the built-in translation interface on the administrative back office, and it’s also easy to customize these by simply copying them to the appropriate destination as shown below.

Using the built-in, Back Office Translation Functions

Go to Localization > Translations and in the section Modify Translations, under Type of translation choose Email templates translations and under Select your theme you can either choose to customize the core templates by selecting Core (no theme selected) or for example using default-bootstrap for the default theme. Once you click Modify, you will be taken to the list of available templates.

Localization Translation Email Templates

Click the one you wish to customize and the editors which allow you to edit the HTML and the plain text version will unfold.

Localization Translations account template

If you have chosen to modify theme-specific templates, you will find the core templates have been copied to the theme’s mails subfolder.

Coding customized Email Templates

If you don’t use the back office functions to customize the email templates for your theme, you can copy the appropriate files manually and modify them using your favorite IDE or text editor. The advantage of this method is that it gives you more fine-grained control over the code used in the templates, compared to using the HTML editor provided in the back office.

Account email templates in the theme folderIn your theme, you need to create the mails subfolder, which will hold customized email templates for each language in an appropriate subfolder. For example, for the English language, you will add your customized templates in your theme’s mails/en subfolder.

Here we are going to modify the default-bootstrap theme. Given that if you update your theme, your changes or additions might be lost, it could be more appropriate to derive a copy of the theme you use and add your templates there instead. Unfortunately PrestaShop still does not support child themes, which would make it easier. In any case, keep a backup of your modified theme and email templates.

As an example, let’s assume you are using the default-bootstrap theme, create the following subfolder prestashop/themes/default-bootstrap/mails/en and copy the original templates account.html and account.txt there.

Now you can modify these templates as desired and they will be used instead of the defaults. In the example files provided in the repository mentioned below, we simply add “Happy Shopping!” to the default templates.

Using alternative Email Templates

The above is fine if you don’t need to send different emails depending on what type of account is created. Here we are going to see how to use a different template for new affiliates than the one which is used for new customers.

As there is no hook which we could use to select a different template conditionally, we need to override the sendConfirmationMail method of the AuthController class.

AuthController Override

To do that, we need to create the file prestashop/override/controllers/front/AuthController.php and implement this method.

AuthController override folder

Our implementation is based on the original method, but with a conditional section that is used to select a different template if the account notification is sent to a new affiliate.

AuthController Affiliate Account Email

We will be using two new template files for that, account-affiliates.html and account-affiliates.txt which we need to place both in prestashop/themes/default-bootstrap/mails/en.

For our customized method to work, it’s important to have overrides enabled, so check that overrides are not disabled under Advanced Parameters > Debug Mode > Disable all overrides : NO. Also clear the cache there if needed.

All files are available in this GitHub repository https://github.com/itthinx/affiliates-pro-prestashop-emails, where you will find them in their corresponding subfolders.

In our affiliate-specific account creation email template, we also provided a new template variable which we use to indicate the URL to the affiliate area: {affiliate_area_url} – we use it in both the HTML and the plain text versions of the email templates.

account-affiliates-customization

Note that you could add any additional template variables in the same manner, or you could use the actionGetExtraMailTemplateVars hook.

Demo Affiliate Email

This is an example of how you could welcome new affiliates to your partner program, using the Affiliates Pro for PrestaShop module and affiliate-specific templates.

, , ,

2 Responses to How to customize PrestaShop Email Templates

  1. Jonas Berglund December 18, 2016 at 10:54 pm #

    Really good explanation, i’m trying to to the translation way but im getting an error message saying

    Forbidden

    You don’t have permission to access /wz4vny1jdtxne6xc/index.php on this server.
    Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

    What could this be?

    • Kento December 22, 2016 at 7:50 am #

      Hi Jonas,

      Is it possible that the directory where the translations are stored is not writable by the server? Can you check the owner and the permissions on that folder?

      Cheers

Leave a Reply