Created
May 26, 2022 10:51
-
-
Save eugenefvdm/2ae416d35b6b5e4b34f88c625cbc5ae8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* disable_invoice_notification.php | |
* | |
* Version 1.0 | |
* | |
* An action hook for WHMCS that allows you to disable sending of invoice reminders for selected payment methods. | |
* | |
* To install: | |
* - Set the array of payment methods that should not send invoice reminders. Typically debit order / direct debit. | |
* - The other array is a list of reminders that should not be sent. | |
* - Then place this script in your whmcs/includes/hooks/ directory. | |
* - Optionally specifiy a log file location. | |
* | |
* Based on Reed Murphy's work at https://gist.github.com/RWJMurphy/3ee801306f2cfca79d61b38041dcdaed | |
* | |
* By: Eugene van der Merwe ([email protected]) +27823096710 I create WHMCS magic and I'm available for consulting | |
* | |
*/ | |
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 = ""; | |
// An array of IDs of payment methods that should not receive invoice notification emails. Replace these with your own. | |
$gateway_names = Array( | |
"debitizedo", // Netcash x-Sage | |
// "directdebit", // Add an array of payment methods that should not send payment reminders | |
); | |
// The names of the email templates that you don't want sent. | |
$message_names = Array( | |
"First Invoice Overdue Notice", | |
"Second Invoice Overdue Notice", | |
"Third Invoice Overdue Notice", | |
); | |
$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', paymentmethod, tblinvoices.id ". | |
"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]; | |
$payment_method = $row[2]; | |
$invoice_id = $row[3]; | |
if ( in_array($payment_method, $gateway_names )) { | |
$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 (%s) for invoice %s because the payment method is %s\n", | |
date("Y-m-d H:i:s"), | |
$pid, | |
$vars['messagename'], | |
$client_name, | |
$client_id, | |
$invoice_id, | |
$payment_method, | |
); | |
$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