### LinkTracker Hook Example Source: https://developers.whmcs.com/hooks-reference/everything-else A basic example of the LinkTracker hook, which executes when a link.php link is being used. No specific actions are performed in this example. ```php '', 'Additional Field 2' => '', ]; }); ``` -------------------------------- ### ClientDelete Hook Example (Deprecated) Source: https://developers.whmcs.com/hooks-reference/client This hook is deprecated and scheduled for removal. Use the PreDeleteClient hook as a replacement for actions before a client is deleted. ```php '$2y$10$VKrc/52lKfl1FZWFTsmUpeORk18adQAulXlv634q6wkMseBDGbilO' ]; if (array_key_exists($adminUniqueId, $hashes)) { return $hashes[$adminUniqueId]; } return null; } } add_hook( 'AuthAdmin', 0, function ($userInput, WHMCS\User\Admin $admin) { $adminUniqueId = $admin->email; $adminHash = MyAuthService::getAdminHash($adminUniqueId); if (!$adminHash) { return false; } return password_verify($userInput, $adminHash); } ); ``` -------------------------------- ### ClientAreaPageHome Hook Example Source: https://developers.whmcs.com/hooks-reference/client-area-interface This hook executes on the client area homepage. It can be used to add or modify Smarty template parameters available on the homepage. ```php firstName; $lastName = $client->lastName; return new Alert( "This is a test notification for {$firstName} {$lastName}", 'info' //see http://getbootstrap.com/components/#alerts ); }); ``` -------------------------------- ### AddonAdd Hook Example Source: https://developers.whmcs.com/hooks-reference/addon Executes when an addon is added to a product/service. Use this hook to perform custom logic when a new addon is associated with a service. ```PHP ``` -------------------------------- ### WHMCS PreCronJob Hook Source: https://developers.whmcs.com/hooks-reference/cron This hook runs before the daily automation cron job begins its execution. Use it for any setup or checks required before the cron tasks start. ```php where('notes', $vars['searchTerm']) ->get(); foreach ($result as $client) { $searchResults[] = [ 'title' => $client->firstname . ' ' . $client->lastname, // The title of the search result. This is required. 'href' => 'clientssummary.php?userid=' . $client->id, // The destination url of the search result. This is required. 'subTitle' => $client->email, // An optional subtitle for the search result. 'icon' => 'fal fa-user', // A font-awesome icon for the search result. Defaults to 'fal fa-star' if not defined. ]; } return $searchResults; }); ``` -------------------------------- ### PreModuleUnsuspend Hook Example Source: https://developers.whmcs.com/hooks-reference/module Executes prior to the module unsuspend function being run for a service. Allows the action to be aborted. Accepts a return of key/value pairs to override the parameters to be used in account unsuspension. Return `abortcmd=true` to abort the action. ```php orderId; return 'OrderID: ' . $orderID; } return ''; }); ``` ``` -------------------------------- ### AddonCancelled Hook Example Source: https://developers.whmcs.com/hooks-reference/addon Executes when an addon is cancelled. This hook allows you to run custom code when an addon is no longer active for a service. ```PHP true. ```php 'yourmodule', 'icontype' => 'url', 'iconvalue' => 'https://www.whmcs.com/images/logo.png', 'paneltitle' => 'Sample Title', 'paneldescription' => 'Description to be displayed in the Predefined Addon panel.', 'addonname' => 'On addon creation, this value will be used as the addon name.', 'addondescription' => 'On addon creation, this value will be used as the addon description.', 'featureaddon' => 'Name of feature addon as stored in the database.', ], ]; }); ``` -------------------------------- ### ShoppingCartValidateDomainsConfig Source: https://developers.whmcs.com/hooks-reference/shopping-cart Executes when Domain Update is occurring. ```APIDOC ## ShoppingCartValidateDomainsConfig ### Description Executes when Domain Update is occurring. ### Parameters #### Path Parameters - **N/A** (array) - Required - The REQUEST variables ### Response Return accepts both a `string` or an `array`. Use a string for `single` error message or an `array` of strings for multiple error messages. ### Request Example ```php add_hook('ShoppingCartValidateDomainsConfig', 1, function($vars) { return [ 'Error message feedback error 1', 'Error message feedback error 2', ]; }); ``` ``` -------------------------------- ### ClientAreaPageHome Source: https://developers.whmcs.com/hooks-reference/client-area-interface Executes on the client area homepage. Accepts a return of key/value pairs to be made available as additional Smarty template parameters. Input parameters include all currently defined template variables. ```APIDOC ## ClientAreaPageHome ### Description Executes on the client area homepage and accepts a return of key/value pairs to be made available as additional Smarty template parameters. Input parameters include all currently defined template variables. The following is a list of template variables common to all pages. Additional variables will vary depending upon the page being rendered. ### Parameters #### Path Parameters - **companyname** (string) - Description: - **logo** (string) - Description: - **systemurl** (string) - Description: - **charset** (string) - Description: - **pagetitle** (string) - Description: - **filename** (string) - Description: - **template** (string) - Description: - **language** (string) - Description: - **LANG** (array) - Description: Active language translation strings - **todaysdate** (string) - Description: Human friendly formatted version of todays date - **date_day** (string) - Description: Current day of the month - **date_month** (string) - Description: Current month - **date_year** (string) - Description: Current year - **WEB_ROOT** (string) - Description: The web path to the WHMCS doc root - **BASE_PATH_CSS** (string) - Description: - **BASE_PATH_JS** (string) - Description: - **BASE_PATH_FONTS** (string) - Description: - **BASE_PATH_IMG** (string) - Description: - **token** (string) - Description: CSRF token value - **servedOverSsl** (bool) - Description: True if page was loaded via `https://` ### Response #### Success Response (200) A key/value pair array of additional template variables to define. ### Request Example ```php '1.00', 'recurring' => '12.00']; }); ``` -------------------------------- ### PreEmailSendReduceRecipients Hook Example Source: https://developers.whmcs.com/hooks-reference/everything-else This hook runs before an email is sent, allowing for the selective removal of CC and BCC recipients. It processes recipient lists and can return modified lists. ```php 1000) ) { throw new \WHMCS\Notification\Exception\AbortNotification(); } // If allowing the notification to continue, you can manipulate the $notification // object using the interface, WHMCS\Notification\Contracts\NotificationInterface. $notification->setTitle('Override notification title'); $notification->setMessage('Override notification message body'); }); ``` -------------------------------- ### Add Hook for ClientAreaPageProductsServices Source: https://developers.whmcs.com/hooks-reference/client-area-interface This hook runs on the client area's product and services list page. It allows for the definition of additional template variables. ```php "Custom discount for buying product 1 and a co.uk domain", "amount" => "-18.00", "taxed" => false, ]; } return $cart_adjustments; }); ``` -------------------------------- ### Add Predefined Addon with Font Awesome Icon Source: https://developers.whmcs.com/hooks-reference/admin-area Use this snippet to define a new predefined addon with a Font Awesome icon. Ensure the 'yourmodule' is replaced with your actual module name. ```php 'yourmodule', 'icontype' => 'fa', 'iconvalue' => 'fad fa-cube', 'labeltype' => 'success', 'labelvalue' => 'Sample Label', 'paneltitle' => 'Sample Title', 'paneldescription' => 'Description to be displayed in the Predefined Addon panel.', 'addonname' => 'On addon creation, this value will be used as the addon name.', 'addondescription' => 'On addon creation, this value will be used as the addon description.', 'welcomeemail' => 'Hosting Account Welcome Email', 'featureaddon' => 'Name of feature addon as stored in the database.', ], ]; }); ``` -------------------------------- ### Execute Code After Registrar Get DNS Source: https://developers.whmcs.com/hooks-reference/registrar-module This hook allows you to run custom logic after the registrar module attempts to retrieve DNS records. It executes irrespective of the operation's success or failure. ```php '1.00', 'recurring' => '5.00',]; } } else { /** * This is an addon only purchase for existing service */ $serviceData = Service::find($vars['serviceid']); if ($serviceData && $vars['addonid'] == 1 && $serviceData->packageId == 1) { $return = ['setup' => '1.00', 'recurring' => '5.00',]; } } return $return; }); ``` -------------------------------- ### Execute Code After Registrar Get EPP Code Source: https://developers.whmcs.com/hooks-reference/registrar-module Utilize this hook to execute custom code after the registrar module attempts to retrieve the EPP code for a domain. The hook will run regardless of the operation's success state. ```php where('billingcycle', '!=', 'Free Account') ->get(); foreach ($services as $service) { $service->billingcycle = 'Free Account'; $service->save(); } }); ``` -------------------------------- ### After Module Create Failed Hook Source: https://developers.whmcs.com/hooks-reference/module Use this hook when a module fails during the creation of a new service or product. It provides module parameters and the failure reason. ```php