Jump to content

Action Hook Basics


mcpacific

Recommended Posts

I have a situation where I need to use an Action Hook. Although I've read the documentation on Action Hooks, I still don't fully understand how to use them.

 

Please correct me if I'm wrong, but from what I've read the first step is to create a file and save it in the includes/hooks folder. This file is a php file and needs to have the custom function declared, as well as the add_hook function.

 

What I don't understand is, how does this Action Hook actually get used(called)? Do you insert it as a server side include on one of your pages?

 

In this case I need to use the hook PreCalculateCartTotals, examine the $_SESSION variables, do some checking and if conditions are met, alter the session.

 

Any help will be greatly appreciated.

Link to comment
Share on other sites

The hook is run when certain things happen in WHMCS, for example when a user logs in certain code is run in whmcs to create the session variables and at the same time the hook "ClientLogin" is called by WHMCS. Likewise when an order has been placed WHMCS does its thing and also calls the hook"AfterShoppingCartCheckout".

 

So to use the action hooks all you need to do is create your custom function (php file) in the includes/hooks directory that you want to run on certain actions from WHMCS.

 

Here is an example of a function to just simply print the variables passed to your custom function from WHMCS

<?php
function create_store($OrderID, $OrderNumber, $InvoiceID, $Products, $Addons, $Domains) {
echo"<pre>";
print_r($OrderID);
print_r($OrderNumber);
print_r($InvoiceID);
print_r($Products);
print_r($Addons);
print_r($Domains);
echo"</pre>";
}
add_hook("AfterShoppingCartCheckout",1,"create_store","");
?>

I hope that explains things a little clearer for you.

Edited by sparky
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated