How to create a custom hook in PrestaShop?

Hooks are gaining importance in PrestaShop shopping cart development day by day as they allow you to add additional functionality at specific points. Today I’ll teach you how to create custom hooks in your PrestaShop module.
Use below steps:
1. Register your hook using function. Place this function into install section.
$this->registerHook(‘displayCustomHtmlContent’);

2. Create hook function.

/**
      * Add the custom content on front
      */
     public function hookDisplayCustomHtmlContent()
     {
         $custom_html = Configuration::get(‘CUSTOMHOOK_CONTENT’);
         $this->context->smarty->assign(‘custom_html’, $custom_html);
         $this->smarty->assign(
             array(
                 ‘custom_html_test’ => $custom_html
             )
         );
         return $this->display(__FILE__, ‘customhook.tpl’);
     }

Prestashop-Developers

3. Display your code anywhere on any tpl using below function.

{hook h=’displayCustomHtmlContent’}

Prestashop

Are you looking fo a certified
Prestashop
Developer for your project?

Share On Facebook
Share On Twitter
Share On Linkedin
Prestashop

We hope you enjoy reading this blog post.

If you want a free audit of your Prestashop project click here

Related Blogs

  • Migrating-Prestashop-store-to-another-domain

    Tips for Migrating PrestaShop Store to Another Domain

    There are various reasons a company changes the domain name of the website. For example, an eCommerce store running for years might have changed its

    Read More