Blog navigation

Blog Rss rss_feed

Hooks in PrestaShop 9: How to Extend Your Store Without Modifying the Core

Hooks in PrestaShop 9: How to Extend Your Store Without Modifying the Core

Hooks are one of the main extension mechanisms in PrestaShop.

They allow a module to react to events or display additional content without changing the PrestaShop core.

The basic idea is simple:

PrestaShop
    ↓
Hook
    ↓
Module

This makes custom development easier to maintain when the store is updated.

Display and Action hooks

Most hooks can be divided into two main groups.

Display hooks

Display hooks are mainly used to add content to a page.

Common examples include:

displayHeader
displayFooter
displayProductActions

A module can return its own template:

public function hookDisplayFooter(array $params)
{
    return $this->display(
        __FILE__,
        'views/templates/hook/footer.tpl'
    );
}

This makes it possible to add new interface elements without editing the main theme files.

Action hooks

Action hooks are used to react to events.

For example:

Order created
    ↓
Hook executed
    ↓
Module sends the order to a CRM

They are commonly used for:

  • order synchronisation;

  • stock updates;

  • sending data to external services;

  • cache management;

  • additional business logic.

Unlike display hooks, action hooks usually do not return content for the customer.

Hooks must be registered

Creating a method such as hookDisplayFooter() is not enough.

The module must also register the hook:

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

PrestaShop can then call:

public function hookDisplayFooter(array $params)
{
    // Module logic
}

There is an important detail when updating an existing module.

If a new hook is added in a later module version, install() will not run again for existing installations.

The hook should therefore be registered through an upgrade script:

function upgrade_module_1_1_0($module)
{
    return $module->registerHook('actionSomething');
}

Missing registration is one of the most common reasons why a hook appears to be correctly implemented but never runs.

Create, update and delete are different events

Choosing the correct hook is just as important as writing its handler.

For example:

actionObjectAddressAddAfter

is related to creating an address.

Editing an existing address is a different operation and may trigger an update hook instead.

When debugging an event, first identify what actually happened:

CREATE
UPDATE
DELETE

Then choose the corresponding hook.

Hooks also work in the modern Back Office

Hooks are not limited to legacy PrestaShop pages.

PrestaShop 9 continues to use them in the Symfony-based Back Office.

A good example is the Grid system.

Modules can use Grid hooks to modify modern administration tables by adding:

columns
filters
actions
bulk actions

This allows modules to extend existing Back Office pages without overriding core controllers or templates.

Hooks in Smarty and Twig

Hooks can also be rendered directly from templates.

In Smarty:

{hook h='displayFooter'}

In Twig:

{{ renderHook('displayFooter') }}

This means the hook system works with both traditional and modern PrestaShop templates.

Creating custom hooks

Modules can also provide their own extension points.

For example:

$this->registerHook('displayMyCustomBlock');

The module can later execute it:

Hook::exec('displayMyCustomBlock', [
    'product' => $product,
]);

This is particularly useful for larger modules that need to allow other modules or custom integrations to extend their behaviour.

Hook or override?

If a task can be solved with a hook, a hook is usually the safer option.

An override creates a stronger dependency on the internal implementation of PrestaShop and can become more difficult to maintain after platform updates.

A hook keeps the core untouched:

PrestaShop Core
      ↓
     Hook
      ↓
Module Logic

Overrides still have their place when no suitable extension mechanism exists, but they should not be the first option for every customisation.

Keep hooks lightweight

Some hooks are executed very frequently.

If every execution performs a slow database query or waits for an external API, the entire store can become slower.

Good practices include:

  • avoiding unnecessary queries;

  • caching reusable results;

  • checking the current page before running expensive logic;

  • moving long-running operations to cron jobs or queues.

A hook that adds only a few hundred milliseconds can become noticeable when it runs on every product page.

How to find the correct hook

A reliable workflow is:

  1. Identify the event you need.

  2. Find the relevant hook in the PrestaShop documentation.

  3. Check where it is executed in the core.

  4. Check which values are available in $params.

  5. Register the hook in the module.

  6. Add an upgrade script for existing installations.

Do not choose a hook only because its name looks similar to the task you are trying to implement.

Hooks remain one of the core extension mechanisms in PrestaShop 9.

They allow modules to:

react to store events;
display custom content;
extend themes;
modify Back Office grids;
integrate with products and orders;
provide extension points for other modules.

The main principle is simple:

if PrestaShop already provides an extension point, use it instead of modifying the core.

This usually results in cleaner modules and makes future PrestaShop updates easier to manage.

Was this blog post helpful to you?

    
👈 Присоединяйтесь к нашему Telegram-каналу!

Будьте в курсе последних новинок и фишек e-commerce: советы, полезные инструменты и эксклюзивные материалы.

No comments at this moment
close

Checkout

close

Favourites

Promo