Difference between revisions of "Hooks"

From WHMCS Documentation

(How It Works)
Line 10: Line 10:
 
*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 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
 
*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
 +
*The four argument is missing (can someone update this information?)
  
 
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.
 
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.

Revision as of 21:02, 6 May 2009

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...

How It Works

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
  • The four argument is missing (can someone update this information?)

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