What are hooks and how do they work in Prestashop?

Qué son y cómo funcionan los hooks en Prestashop

Like a Swiss watch, any PrestaShop store is made up of a surprising number of mechanisms and parts that facilitate its correct operation day after day. Within this collection are the essential " hooks " where the content of the modules that make up the digital store is associated.

What are "hooks"?

For those who still can't find their way around (and to find the starting point for this educational post) we will go to the administration area of ​​our PrestaShop store. Through the “ Modules ” option in the Back office we will click on “Module positions” to find the list of modules that we have active on the website. Each and every one of the modules that will appear in the list are associated with the hook that appears just above each block.

Qué son los hooks en PrestaShop

These anchor points that allow you to link your code to specific functionalities such as displaying offers or creating a user account are defined by a name according to the type (which we will see below), such as 'displayRightColumn', 'displayMobileTopSiteMap', 'actionProdcutListOverride' or 'actionProductDelete' and would be as follows:

In the ' actionProductAdd' hook, based on the creation of products, we can find the Module of the best-selling items of the week .

modules009-liveEdit Many of these "hooks" are blocks visible to the public from the store, but others are hidden and can only be seen internally. Luckily for our curiosity, PrestaShop allows us to see which area of ​​our website they work in through " Live Edit " or edit live: the button that appears to the right of the list of modules.

We will be automatically redirected to the store's Front Office to check the position, move and even delete modules on the fly, thus showing the hooks to which they are associated.

Types of hooks in PrestaShop and how they work

Within the functionalities of hooks there are two large groups: action and observation.

  • Action hooks : as their name suggests, these hooks will be responsible for interacting when the client accesses one of the modules, such as: sending a confirmation email when the client creates an account or adding discounts to the cart for certain offers. These invisible hooks must be executed through "triggers", that is, calls to specific actions when the module executes its instruction.
Cómo funcionan los hooks de acción en PrestaShop
  • Display hooks , on the other hand, perform a purely visual function, allowing you to display columns, lists of products or images. These types of hooks with the "display" prefix are the most commonly used in PrestaShop and appear in almost every corner of the store. Take a look at the list of modules in your digital store through the back office, and you'll see how many visual hooks you've accumulated.
Cómo funcionan los hooks de display en PrestaShop

Any questions to resolve?

Please use the comments box to share your experience in detail. At Línea Gráfica we are experts in PrestaShop , so if after what we have said you need help structuring hooks, you just have to contact us.

Updated on