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’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.
Click the one you wish to customize and the editors which allow you to edit the HTML and the plain text version will unfold.
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.
In 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.
To do that, we need to create the file prestashop/override/controllers/front/AuthController.php
and implement this method.
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.
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.
Note that you could add any additional template variables in the same manner, or you could use the actionGetExtraMailTemplateVars
hook.
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.
Thanks for writing article on email templates [explained guide], it has very useful information.
Hi Siddharth,
Thanks, glad to hear it was useful for you!
Cheers
Hi, Did all this, tried both the translation option and changing the template on the server. But non of the changes have any effect. It’s also strange the changes made in one solution do not show up in the other. But they are saved and do show up even on an other computer with an other browser. But only either in the translation section or on the server. Other changes like product updates in the backoffice or adjustments on the server work as expected.
Hi,
I think you need to review your site’s template compilation and cache settings – you can see the related settings here: http://doc.prestashop.com/display/PS17/Performance
Cheers
Curious, how does Prestashop compare to WooCommerce? Which is more superior?
Hi Austin,
For what it’s worth, I find WooCommerce easier to handle and more powerful both as a user and a developer. But then it’s a matter of what system suits your specific requirements most.
Cheers
Well done, it work for me
Thanks for detail post!
Great to hear, many thanks for your feedback 🙂
Hi, Did all this, tried both the translation option and changing the template on the server. But non of the changes have any effect. It’s also strange the changes made in one solution do not show up in the other. But they are saved and do show up even on an other computer with an other browser. But only either in the translation section or on the server. Other changes like product updates in the backoffice or adjustments on the server work as expected.
Hi Gerard,
Maybe it’s a problem with the cache, you can try to clear the cache.
Also, you can check if your theme has a ‘mails’ folder
Kind Regards,
Antonio B.
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?
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