Difference between revisions of "How to Make a New Hook"

From Phoenix Cart User Guide
Line 2: Line 2:
 
<span class="btn-grey" style="color:#0088dd;">'''&#x1F809; [[FAQS TIPS & TRICKS]]'''</span>
 
<span class="btn-grey" style="color:#0088dd;">'''&#x1F809; [[FAQS TIPS & TRICKS]]'''</span>
 
<hr>
 
<hr>
 +
 +
 +
A hook file listens and inserts its output wherever it is called in the core code.
 +
 +
There are existing hook calls throughout the core code.
 +
 +
In this simple example, a message is displayed in the shop on checkout_confirmation.php.
 +
 +
That page is not modular, so a content module cannot be used so a hook is needed.
 +
 +
Looking at checkout_confirmation.php:
 +
 +
https://github.com/CE-PhoenixCart/Phoenix/blob/master/templates/default/includes/pages/checkout_confirmation.php#L159
 +
 +
A hook call can be seen already in place:
 +
 +
<pre>echo $OSCOM_Hooks->call('siteWide', 'injectFormDisplay');</pre>
 +
 +
This shows '''siteWide''', the Group and '''injectFormDisplay''', the Action.
 +
 +
It can be seen that the hook call is placed just before the '''Finalise Order''' button so that is where the hook file output will be inserted.
 +
 +
There is already a hook file that listens for that call - '''MATC.php''' that shows the Legal agreements.
 +
 +
 +
 +
So, I need to name my new hook file according to the sorting rules explained by ecartz in the previous posts.
 +
 +
The rules are numbers, then uppercase letters (in alphabetical order), then _, then lowercase letters.
 +
 +
I want my message to show before MATC so eventually decided to name it Cmessage.php
 +
 +
To make the most of the template system, I created that new file in /templates/override/includes/hooks/shop/checkout_confirmation/ (I had to create the directories to follow that structure).
 +
The file could be in whatever template that is being used, that is, whatever has been selected in admin->Configuration->My Store->Template Selection.
 +
In that file I used the code:
 +
  
 
<div class="mainpage_box">
 
<div class="mainpage_box">

Revision as of 05:43, 26 February 2021

<historylink type="back">🠈 Back</historylink> 🠉 FAQS TIPS & TRICKS



A hook file listens and inserts its output wherever it is called in the core code.

There are existing hook calls throughout the core code.

In this simple example, a message is displayed in the shop on checkout_confirmation.php.

That page is not modular, so a content module cannot be used so a hook is needed.

Looking at checkout_confirmation.php:

https://github.com/CE-PhoenixCart/Phoenix/blob/master/templates/default/includes/pages/checkout_confirmation.php#L159

A hook call can be seen already in place:

echo $OSCOM_Hooks->call('siteWide', 'injectFormDisplay');

This shows siteWide, the Group and injectFormDisplay, the Action.

It can be seen that the hook call is placed just before the Finalise Order button so that is where the hook file output will be inserted.

There is already a hook file that listens for that call - MATC.php that shows the Legal agreements.


So, I need to name my new hook file according to the sorting rules explained by ecartz in the previous posts.

The rules are numbers, then uppercase letters (in alphabetical order), then _, then lowercase letters.

I want my message to show before MATC so eventually decided to name it Cmessage.php

To make the most of the template system, I created that new file in /templates/override/includes/hooks/shop/checkout_confirmation/ (I had to create the directories to follow that structure). The file could be in whatever template that is being used, that is, whatever has been selected in admin->Configuration->My Store->Template Selection. In that file I used the code:


Hook1.png



Construction.png
This page is in progress
Please visit again soon for additions and changes

Phoenix Cart User Guide, like CE Phoenix Cart, is free to use but is maintained by unpaid volunteers.

Code references are licensed under a Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales License.
All other content is the reserved Intellectual Property and Copyright of phoenixcart.org