Making a Hook

Open to all! Ask other shopowners for help.
Post Reply
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Making a Hook

Post by heatherbell »

I have made a hook named checkoutConfirmation to show a message on checkout_confirmation using listen_injectFormDisplay.
It works but want it to show above the existing Legal MATC - it currently shows below this.
How do I change it's position?
Thank you for any pointers.


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Making a Hook

Post by ecartz »

Look up the name of the MATC hook and then pick a name for your new hook that sorts before it.

MATC: hook_shop_siteWide_MATC

So the hook name is MATC (who'd have guessed). Sorting after it would be MATD, atc, zz, _MATC, etc. Before it would be MATB, AAA, 0MATC, 9MATC, etc. The rules are numbers, then uppercase letters (in alphabetical order), then _, then lowercase letters.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Making a Hook

Post by heatherbell »

ecartz wrote: Tue Feb 23, 2021 1:40 pm Look up the name of the MATC hook and then pick a name for your new hook that sorts before it.

MATC: hook_shop_siteWide_MATC

So the hook name is MATC (who'd have guessed). Sorting after it would be MATD, atc, zz, _MATC, etc. Before it would be MATB, AAA, 0MATC, 9MATC, etc. The rules are numbers, then uppercase letters (in alphabetical order), then _, then lowercase letters.
The sorting of lower case after upper case caught me out so, in my case, changing name from checkoutConfirmation to CheckoutConfirmation makes it show above MATC as expected.
Thanks so much for helping and for the explanation.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Making a Hook

Post by heatherbell »

Looking at this more at https://github.com/gburton/CE-Phoenix/wiki/Hooks
Page
For hooks that should only run on a specific page. These hooks are named based on the page name, which is the file name without the .php at the end. For example, we might talk about index, product_info, create_account, or checkout_shipping hooks.
In my case (a hook to show message on checkout_confirmation) I currently have hook_shop_siteWide_CheckoutConfirmation which works (because I have code that checks $PHP_SELF) but if I understand the above correctly, what would be the correct naming and file location - hook_shop_Page_checkout_confirmation in /hooks/shop/Page/ or hook_shop_Page_checkout_confirmation_whatever in /hooks/shop/Page/checkout_confirmation/ which I presume would negate the need for the $PHP_SELF check.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Making a Hook

Post by ecartz »

hook_shop_checkout_confirmation_Message
templates/override/includes/hooks/shop/checkout_confirmation/Message.php

I changed the hook name just because I find checkout_confirmation_CheckoutConfirmation confusing. If it makes sense to you, it's fine as is.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Making a Hook

Post by heatherbell »

Thanks so much for shining that light - all becomes clear!
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Making a Hook

Post by heatherbell »

There are 2 checkout_confirmation.php files in core, one in root and one in /templates/default/includes/pages/
I guess the one in /templates/default/includes/pages/ would be known as the "template" file? Otherwise what would the correct term be?
What would be the correct term for the one in root?


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply