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...
Contents |
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 variables 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:
function create_forum_account($vars) {
print_r($vars);
}
add_hook("ClientAdd",1,"create_forum_account");
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.
Below is a full list of hook points you can tap into and the variables that are passed into each one in the $vars array:
ClientAdd - userid, firstname, lastname, etc... ClientEdit - userid, firstname, lastname, etc... ClientLogin - userid ClientLogout - userid ClientChangePassword - userid, password ClientDetailsValidation - $_POST ClientClose - userid ClientDelete - userid PreDeleteClient - userid
ContactAdd - userid, firstname, lastname, etc... ContactEdit - userid, contactid, firstname, lastname, etc...
AfterModuleCreate - params AfterModuleSuspend - params AfterModuleUnsuspend - params AfterModuleTerminate - params AfterModuleChangePassword - params AfterModuleChangePackage - params AddonActivation - id, userid, serviceid, addonid PreDomainRegister - params, domain AfterRegistrarRegistration - params AfterRegistrarTransfer - params AfterRegistrarRenewal - params AdminServiceEdit - serviceid CancellationRequest - userid, relid, reason, type AfterProductUpgrade - upgradeid AfterConfigOptionsUpgrade - upgradeid
ShoppingCartValidateProductUpdate - runs after updating cart, can use global $errormessage
to pass back error
ShoppingCartValidateCheckout - runs when checkout is clicked, can use global $errormessage
to pass back error
PreCalculateCartTotals - products, addons, domains, paymentmethod, etc...
PreShoppingCartCheckout - as above
AfterShoppingCartCheckout - OrderID, OrderNumber, InvoiceID, Products, Addons, Domains
InvoiceCreationPreEmail - invoiceid
InvoiceCreated - invoiceid
InvoicePaid - invoiceid
InvoiceUnpaid - invoiceid
InvoiceCancelled - invoiceid
InvoiceRefunded - invoiceid
UpdateInvoiceTotal - invoiceid
AddInvoicePayment - invoiceid
LogTransaction - date, gateway, data, result
AddTransaction - id, userid, currency, gateway, date, description, amountin, fees
amountout, rate, transid, invoiceid, refundid
ManualRefund - transid, amount
AddInvoiceLateFee - invoiceid
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
TicketOpenAdmin - ticketid, userid, deptid, deptname, subject, message, priority
TicketAddNote = ticketid, message, adminid
AdminLogin - adminid AdminLogout - adminid AdminHomepage - none AnnouncementAdd - announcementid, date, title, announcement, published AnnouncementEdit - announcementid, date, title, announcement, published
ViewOrderDetailsPage - can be used to run code & output in order details view (eg. custom
fraud checks) - orderid, ordernum, amount, paymentmethod, invoiceid, status
ClientAreaPage - can reference $smarty for defining template vars (no variables)
DailyCronJob - can be used to run code daily for custom processes (no variables)