Registering hooks with package.json and hooks.json
Key Takeaway
A cartridge registers its hooks with a package.json in its top-level directory whose hooks property points to hooks.json. The cartridge must also be registered in Business Manager to each site that needs the hooks.
A hook lets you run your own script at a named extension point. The extension point can be built in, such as before or after an OCAPI call. It can also be a custom one that you define and call from your own code. A cartridge registers its hooks with two files: package.json points to hooks.json, and hooks.json maps each extension point name to the script that implements it. Both files and the site registration in Business Manager are needed before a hook can run on a site.
Two kinds of hooks
OCAPI hooks are extension points that B2C Commerce provides so you can run scripts before or after specific OCAPI calls.
Custom hooks are extension points that you define yourself. You call them with the dw.system.HookMgr class from either OCAPI code or storefront code. Because both kinds of code can call the same custom hook, custom hooks are useful when several channels share the same site.