Adding a hook

You might want, at some points, to add your own hooks. In PrestaShop 1.5/1.6, you do not need to add it manually in your database to create a new hook anymore. In fact, you just have to place your hook's trigger in the PHP file or template file you want (with the same syntax described at the beginning of the Triggering hooks section), and then attach the module to the new hook with the registerHook method.

The registerHook method will automatically create the hook in the database if it does not already exist. It is not as efficient as an event listener system you can find in other frameworks, but it's still powerful and effective.

Get PrestaShop Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.