Skip to content

Instantly share code, notes, and snippets.

@mhrubel
Forked from Pierowheelz/disable_zero_invoices.php
Created February 8, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhrubel/0946bda57e444e7cf0d59ffded21c83a to your computer and use it in GitHub Desktop.
Save mhrubel/0946bda57e444e7cf0d59ffded21c83a 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