Skip to content

Instantly share code, notes, and snippets.

@Pierowheelz
Created June 14, 2018 22:36
Show Gist options
  • Save Pierowheelz/817f9f85ea1d506ba7852b1d1e5ec528 to your computer and use it in GitHub Desktop.
Save Pierowheelz/817f9f85ea1d506ba7852b1d1e5ec528 to your computer and use it in GitHub Desktop.
A hook for WHMCS which disables email notifications for invoices with a zero total. Modified from existing code to use the new Capsule database handler ( http://www.whmcsjet.com/how-to-disable-invoice-generation-for-0-00-invoices/ ).
<?php
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
use WHMCS\Database\Capsule;
function disable_00_invoices($vars) {
$merge_fields = array();
$email_template_name = $vars['messagename']; # Email template name being sent
$relid = $vars['relid']; # Related ID it's being sent for - client ID, invoice ID, etc...
//Checking for certain template name, if so - this is our case
if ($email_template_name == "Invoice Created" || $email_template_name == "Invoice Payment Confirmation"){
//getting total of the invoice
$inv_total = Capsule::table('tblinvoices')->where('id', $relid)->pluck('total');
if( is_array($inv_total) ){
$inv_total = $inv_total[0];
}
//if it is equal to '0.00' we disable email sending
if ( null !== $inv_total && '0.00' == $inv_total )
$merge_fields['abortsend'] = true;
}
return $merge_fields;
}
add_hook("EmailPreSend",1,"disable_00_invoices");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment