Presenting the two types of hook
If you connect to your database and select all the rows of the table named prefix_hook
, you may see that the name values almost always follow the same pattern. The name
column is always in camelCase and sometimes starts with action
or display
. There we are: we found the two main types of hooks used by PrestaShop!
The display
hooks are visual and are executed in one, or sometimes many, Smarty or Twig templates arbitrarily, and they trigger the registered module(s) to insert custom HTML. Some parameters can be retrieved by the called modules. They run like actions
in WordPress, if you know them. For example, if you want a module to add a block of text inside a page, you can use a display
hook.
The action
hooks are invisible because they only have an effect on the payload data transmitted as referenced parameters. To continue with the WordPress comparison, they can be compared to WordPress filters. For example, if you have an array of products to...