Back to Top

Email theme in PrestaShop using module

Updated 15 April 2024

In this blog, we are going to learn how to add email theme in PrestaShop using module.

In PrestaShop you can add new theme folder directly in mail/themes, but this can’t be install/uninstall quickly as module.

Email theme in PrestaShop using module

Firstly you have to create your own templates for mails as it is given in mails/theme/ and keep it in your module.
Follow the same folder structure as given below

├── modules
    ├── yourmodule
        ├── mails
        │     └── themes
        |           └──wk_modern
        |                 ├assets---contains all assets going to use
        |                 ├components---contains header, footer, layout
        |                 |             twig files
        |                 ├core---contains all the mail templates available
        |                 |       in PS as twig files
        |                 └modules --- contains all the modules related
        |                              mails available in PS modules
        |
        |
        └── yourmodule.php

Here, we are going to use the hook actionListMailTheme which list new mail theme directly from module. Please follow the below code for module main file.

<?php
use PrestaShop\PrestaShop\Core\MailTemplate\Layout\Layout;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCollectionInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeScanner;

class WkModern extends Module
{
    public function __construct()
    {
        $this->name = 'WkModern';
        $this->tab = 'theme';
        $this->version = '1.0.0';
        $this->author = 'Author';
        $this->need_instance = 0;
        parent::__construct();
        $this->displayName = $this->l('Modern Email Theme');
        $this->description = $this->l('Email theme module to modifiy emails.');
        $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);        
    }

    public function install()
    {
        return parent::install()
            && $this->registerHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    }

    public function uninstall()
    {
        return parent::uninstall()
            && $this->unregisterHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    }

    public function enable($force_all = false)
    {
        return parent::enable($force_all)
            && $this->registerHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    }

    public function disable($force_all = false)
    {
        return parent::disable($force_all)
            && $this->unregisterHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    }
   
    public function hookActionListMailThemes(array $hookParams)
    {
        if (!isset($hookParams['mailThemes'])) {
            return;
        }
        /** @var ThemeCollectionInterface $themes */
        $themes = $hookParams['mailThemes'];
        $scanner = new FolderThemeScanner(__DIR__);
        $wk_modern = $scanner->scan(__DIR__.'/mails/themes/wk_modern');
        if (null !== $wk_modern && $wk_modern->getLayouts()->count() > 0) {
            $themes->add($wk_modern);
        }
    }
}

Your theme is listed in “Design > Email Theme” page and preview the wk_modern theme, same as default PrestaShop email theme is shown. You can click on the view button and see all the available email templates in that particular theme.

Searching for an experienced
Prestashop Company ?
Find out More

In this example we have created an email theme with name wk_modern as shown in attached image below .

Email theme in PrestaShop using module

That’s all about Email theme in PrestaShop using module. Hope it will help you.

Concluding this blog, I hope it proves helpful to you. If you encounter any issues or have doubts about the aforementioned process, please don’t hesitate to contact us through the comment section.

Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at [email protected]

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home