Page 1 of 1

Making a Hook

Posted: Tue Feb 23, 2021 1:28 pm
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.

Re: Making a Hook

Posted: Tue Feb 23, 2021 1:40 pm
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.

Re: Making a Hook

Posted: Tue Feb 23, 2021 2:23 pm
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.

Re: Making a Hook

Posted: Tue Feb 23, 2021 5:59 pm
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.

Re: Making a Hook

Posted: Tue Feb 23, 2021 6:11 pm
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.

Re: Making a Hook

Posted: Tue Feb 23, 2021 6:13 pm
by heatherbell
Thanks so much for shining that light - all becomes clear!

Re: Making a Hook

Posted: Sun Mar 07, 2021 1:56 pm
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?