Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paradigmaweb/611548e047f83cde68eecadd2383c294 to your computer and use it in GitHub Desktop.
Save paradigmaweb/611548e047f83cde68eecadd2383c294 to your computer and use it in GitHub Desktop.
WHMScripts: Disabling invoice creation emails in WHMCS on a per-client basis

If you’re using WHMCS to manage your cPanel shared servers, this is probably a request that you’ve received a few times. You have clients that are set up to pay invoices automatically from their credit cards, and they’d rather not receive the “Invoice Created” or “Invoice Payment Reminder” emails every month.

Normally WHMCS only allows you to disable these emails globally but, by making use of the EmailPreSend action hook, we can set up a list of clients not to receive these.

To get started just download the following script, change the file extension to .php, edit it to set up the $client_ids and place it in your WHMCS /includes/hooks/ directory

Please note, this script doesn’t disable only the automatically sent invoice notification emails, but also blocks manual sending of these for the selected clients.

(originally posted at http://whmscripts.net/whmcs/2011/disabling-invoice-creation-emails-in-whmcs-on-a-per-client-basis/)

<?php
/*
* disable_invoice_notification.php
* Version 1.0
*
* An action hook for WHMCS that allows you to disable sending of invoice
* creation notifications for selected clients.
*
* To install, just set the $client_ids and (optionally) $logfile variables
* then place this script in your whmcs/includes/hooks/ directory.
*
* Tested with WHMCS 4.5.2
*
* Reed Murphy <reed@whitedoggreenfrog.com> 2010
*
* For more free cPanel / WHM / WHMCS scripts, check out http://whmscripts.net/
*/
function hook_disable_invoice_notification($vars) {
// If $logfile is not blank, messages about emails not sent will be
// logged to this file.
// $logfile = "/home/whmcs/presendemail.log";
// $logfile = "";
$logfile = "";
// An array of IDs of clients that should not receive invoice notification
// emails. Replace these with your own.
$client_ids = Array(
"1234",
"999"
);
// The names of the email templates that you don't want sent.
$message_names = Array(
"Credit Card Invoice Created",
"Invoice Created",
"Invoice Payment Reminder"
);
$merge_fields = array();
if (in_array($vars['messagename'], $message_names)) {
$invoice_id = mysql_real_escape_string($vars['relid']);
$query =
"SELECT `userid`, CONCAT_WS(' ', `firstname`, `lastname`) as 'name' ".
"FROM `tblinvoices` ".
"JOIN `tblclients` ON `tblinvoices`.`userid` = `tblclients`.`id` ".
"WHERE `tblinvoices`.`id` = '" . $invoice_id ."'";
$r = full_query($query);
if ($r) {
$row = mysql_fetch_row($r);
$client_id = $row[0];
$client_name = $row[1];
if (in_array($client_id, $client_ids)) {
$merge_fields['abortsend'] = true; // don't send email
if ($logfile) {
$pid = getmypid();
$logline = sprintf(
"%s pre_send_email[%d]: ".
"Not sending email '%s' to client %s\n",
date("Y-m-d H:i:s"),
$pid,
$vars['messagename'],
$client_name
);
$fh = fopen($logfile, "a");
fwrite($fh, $logline);
fclose($fh);
}
}
}
}
return $merge_fields;
}
add_hook("EmailPreSend", 10, "hook_disable_invoice_notification");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment