mcpacific Posted May 13, 2009 Share Posted May 13, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
mcpacific Posted May 14, 2009 Author Share Posted May 14, 2009 Ok, I guess I figured this out. I was wondering why all the documentation talked about how to create an action hook but nothing about how to actually use it... Now I understand that creating the action hook file IS how to use it. LOL 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted May 14, 2009 Share Posted May 14, 2009 (edited) 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 May 14, 2009 by sparky 0 Quote Link to comment Share on other sites More sharing options...
mcpacific Posted May 14, 2009 Author Share Posted May 14, 2009 Most definitely! Thank you!! I just didn't understand that WHMCS would somehow be able to find my php file without me first specifying its filename somewhere... 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.