Difference between revisions of "Hooks"

From WHMCS Documentation

(Hook Points)
(Hook Points)
Line 19: Line 19:
  
 
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:
 
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:
 +
 +
===Clients===
  
 
  ClientAdd - userid, firstname, lastname, etc...  
 
  ClientAdd - userid, firstname, lastname, etc...  
 
  ClientEdit - userid, firstname, lastname, etc...
 
  ClientEdit - userid, firstname, lastname, etc...
  ContactAdd - userid, firstname, lastname, etc...
+
  ClientLogin - userid
 +
ClientLogout - userid
 +
ClientChangePassword - userid, password
 
  ClientDetailsValidation - $_POST
 
  ClientDetailsValidation - $_POST
ContactEdit - userid, contactid, firstname, lastname, etc...
 
ClientChangePassword - userid, password
 
 
  ClientClose - userid
 
  ClientClose - userid
 
  ClientDelete - userid
 
  ClientDelete - userid
ClientLogin - userid
 
ClientLogout - userid
 
AdminLogin - adminid
 
AdminLogout - adminid
 
AdminHomepage - none
 
CancellationRequest - userid, relid, reason, type
 
 
  PreDeleteClient - userid
 
  PreDeleteClient - userid
  LogTransaction - date, gateway, data, result
+
 
  AddTransaction - id, userid, currency, gateway, date, description, amountin, fees
+
===Contacts===
              amountout, rate, transid, invoiceid, refundid
+
 
UpdateInvoiceTotal - invoiceid
+
  ContactAdd - userid, firstname, lastname, etc...
AddInvoicePayment - invoiceid
+
  ContactEdit - userid, contactid, firstname, lastname, etc...
ManualRefund - transid, amount
+
 
InvoicePaid - invoiceid
+
===Products/Services===
 +
 
 
  AfterModuleCreate - params
 
  AfterModuleCreate - params
 
  AfterModuleSuspend - params
 
  AfterModuleSuspend - params
Line 49: Line 46:
 
  AfterModuleChangePackage - params
 
  AfterModuleChangePackage - params
 
  AddonActivation - id, userid, serviceid, addonid
 
  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
 +
 +
===Order Process===
 +
 
  PreCalculateCartTotals - products, addons, domains, paymentmethod, etc...
 
  PreCalculateCartTotals - products, addons, domains, paymentmethod, etc...
 
  PreShoppingCartCheckout - as above
 
  PreShoppingCartCheckout - as above
 
  AfterShoppingCartCheckout - OrderID, OrderNumber, InvoiceID, Products, Addons, Domains
 
  AfterShoppingCartCheckout - OrderID, OrderNumber, InvoiceID, Products, Addons, Domains
 +
 +
===Invoicing===
 +
 
  InvoiceCreationPreEmail - invoiceid
 
  InvoiceCreationPreEmail - invoiceid
 
  InvoiceCreated - invoiceid
 
  InvoiceCreated - invoiceid
 +
InvoicePaid - invoiceid
 
  InvoiceUnpaid - invoiceid
 
  InvoiceUnpaid - invoiceid
 
  InvoiceCancelled - invoiceid
 
  InvoiceCancelled - invoiceid
 
  InvoiceRefunded - invoiceid
 
  InvoiceRefunded - invoiceid
  PreDomainRegister - params, domain
+
  UpdateInvoiceTotal - invoiceid
  AfterRegistrarRegistration - params
+
AddInvoicePayment - invoiceid
  AfterRegistrarTransfer - params
+
LogTransaction - date, gateway, data, result
  AfterRegistrarRenewal - params
+
  AddTransaction - id, userid, currency, gateway, date, description, amountin, fees
 +
              amountout, rate, transid, invoiceid, refundid
 +
  ManualRefund - transid, amount
 +
  AddInvoiceLateFee - invoiceid
 +
 
 +
===Support Tickets===
 +
 
 
  TicketOpen - ticketid, userid, deptid, deptname, subject, message, priority
 
  TicketOpen - ticketid, userid, deptid, deptname, subject, message, priority
 
  TicketAdminReply - ticketid, replyid, deptid, deptname, subject, message, priority
 
  TicketAdminReply - ticketid, replyid, deptid, deptname, subject, message, priority
Line 66: Line 84:
 
  TicketUserReply - ticketid, replyid, userid, deptid, deptname, subject, message
 
  TicketUserReply - ticketid, replyid, userid, deptid, deptname, subject, message
 
               priority, status
 
               priority, status
 +
TicketOpenAdmin - ticketid, userid, deptid, deptname, subject, message, priority
 
  TicketAddNote = ticketid, message, adminid
 
  TicketAddNote = ticketid, message, adminid
  AfterProductUpgrade - upgradeid
+
 
  AfterConfigOptionsUpgrade - upgradeid
+
===Admin===
  ClientAreaPage - none - can reference $smarty for defining template vars
+
 
  AddInvoiceLateFee - invoiceid
+
  AdminLogin - adminid
  ViewOrderDetailsPage - orderid, ordernum, amount, paymentmethod, invoiceid, status
+
  AdminLogout - adminid
  DailyCronJob - none
+
  AdminHomepage - none
 +
AnnouncementAdd - announcementid, date, title, announcement, published
 +
  AnnouncementEdit - announcementid, date, title, announcement, published
 +
 
 +
===Miscellaneous===
 +
 
 +
  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)

Revision as of 16:08, 10 August 2010

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 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");
  • 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 $vars array:

Clients

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

Contacts

ContactAdd - userid, firstname, lastname, etc...
ContactEdit - userid, contactid, firstname, lastname, etc...

Products/Services

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

Order Process

PreCalculateCartTotals - products, addons, domains, paymentmethod, etc...
PreShoppingCartCheckout - as above
AfterShoppingCartCheckout - OrderID, OrderNumber, InvoiceID, Products, Addons, Domains

Invoicing

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

Support Tickets

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

Admin

AdminLogin - adminid
AdminLogout - adminid
AdminHomepage - none
AnnouncementAdd - announcementid, date, title, announcement, published
AnnouncementEdit - announcementid, date, title, announcement, published

Miscellaneous

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)