Difference between revisions of "Hooks"

From WHMCS Documentation

(Replaced content with "<div class="docs-alert-info"> <span class="title">Note</span><br /> This page has moved to [https://developers.whmcs.com/hooks/ https://developers.whmcs.com/hooks/] </div>")
 
(35 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Action hooks allow you to add your own code that will run when specific actions occur in WHMCS.  For example, this can be used for things like performing other actions when an order is placed, sending an SMS message when a support ticket is opened, updating a users details in another application when a change is made in WHMCS, and many more...
+
<div class="docs-alert-info">
 
+
<span class="title">Note</span><br />
==How It Works==
+
This page has moved to [https://developers.whmcs.com/hooks/ https://developers.whmcs.com/hooks/]
 
+
</div>
Hooks work by creating a file in the includes/hooks folder.  Within the file, you need to declare a function that performs the action you want to run.  That function will be passed an array of $args from WHMCS, and the values you get depend on the hook being called.  All hooks and the variables they will be passed are listed below.  After defining your function, you then add the hook to WHMCS which is done by calling the add_hook function:
 
 
 
add_hook("ClientAdd",1,"create_forum_account","");
 
 
 
*The first part defines the hook point.  This must be one of the values from below: ClientAdd, AddInvoicePayment, TicketOpen, etc...
 
*The number defines the priority so if you have more than 1 hook for the ClientAdd function, the order in which the hooks should run
 
*The third argument tells WHMCS which function to run at this hook point and so this is the name of the function which you have written in your hook file
 
 
 
Two example hook files are included which you'll find in the hooks folder - one basic example showing the file format and another providing a fully working example of a ClientAdd hook to validate an entered Tax/VAT ID Number.
 
 
 
==Hook Points==
 
 
 
Below is a full list of hook points you can tap into and the variables that are passed into each one in the $args array:
 
 
 
ClientAdd - userid, firstname, lastname, etc...  
 
ClientEdit - userid, firstname, lastname, etc...
 
ContactAdd - userid, firstname, lastname, etc...
 
ClientDetailsValidation - $_POST
 
ContactEdit - userid, contactid, firstname, lastname, etc...
 
ClientChangePassword - userid, password
 
ClientDelete - userid
 
ClientLogin - userid
 
ClientLogout - userid
 
CancellationRequest - userid, relid, reason, type
 
PreDeleteClient - userid
 
LogTransaction - date, gateway, data, result
 
AddTransaction - id, userid, currency, gateway, date, description, amountin, fees
 
              amountout, rate, transid, invoiceid, refundid
 
UpdateInvoiceTotal - invoiceid
 
AddInvoicePayment - invoiceid
 
ManualRefund - transid, amount
 
InvoicePaid - invoiceid
 
AfterModuleCreate - params
 
AfterModuleSuspend - params
 
AfterModuleUnsuspend - params
 
AfterModuleTerminate - params
 
AfterModuleChangePassword - params
 
AfterModuleChangePackage - params
 
PreCalculateCartTotals - products, addons, domains, paymentmethod, etc...
 
PreShoppingCartCheckout - as above
 
AfterShoppingCartCheckout - OrderID, OrderNumber, InvoiceID, Products, Addons, Domains
 
InvoiceCreated - invoiceid
 
AfterRegistrarRenewal - params
 
AfterRegistrarRegistration - params
 
AfterRegistrarTransfer - params
 
TicketOpen - ticketid, userid, deptid, deptname, subject, message, priority
 
TicketAdminReply - ticketid, replyid, deptid, deptname, subject, message, priority
 
              admin, status
 
TicketUserReply - ticketid, replyid, userid, deptid, deptname, subject, message
 
              priority, status
 
AfterProductUpgrade - upgradeid
 
AfterConfigOptionsUpgrade - upgradeid
 
ClientAreaPage - none - can reference $smarty for defining template vars
 
AddInvoiceLateFee - invoiceid
 
DailyCronJob - none
 

Latest revision as of 10:45, 4 January 2017

Note
This page has moved to https://developers.whmcs.com/hooks/