Bertie Posted September 25, 2019 Share Posted September 25, 2019 Hi, Can't post in the original thread: Basically emails are still being sent out when £0 invoices are being raised and causing a bit of confusion with clients so would like to get it disabled. It seems the HOOK I have is not working. I don't mind £0 invoices being raised as I don't think that can be disabled but would love to stop them from being sent out to clients when they raise. This is the hook I have so far: <?php function disable_00_invoices($vars) { $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 $result = select_query('tblinvoices', 'total', array("id" => $relid)); $data = mysql_fetch_assoc($result); //if it is equal to '0.00' we disable email sending if (isset($data['total']) && $data['total'] == '0.00') $merge_fields['abortsend'] = true; } return $merge_fields; } add_hook("EmailPreSend",1,"disable_00_invoices"); WHMCS Version:7.7.1 Any help will be appreciated. Cheers, 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 25, 2019 Share Posted September 25, 2019 Hi. You can use this hook: <?php use WHMCS\Database\Capsule; add_hook('EmailPreSend', 1, function($vars) { $email_template_name = $vars['messagename']; $merge_fields = []; if($email_template_name == 'Invoice Created' || $email_template_name == 'Invoice Payment Confirmation'){ $total = Capsule::table('tblinvoices') ->where('id', $vars['relid']) ->value('total'); if($total == '0.00'){ $merge_fields['abortsend'] = true; } } return $merge_fields; }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 25, 2019 Share Posted September 25, 2019 3 hours ago, Bertie said: This is the hook I have so far that's an old hook! 👴 I think to rewrite it for Capsule, it should be... <?php # Disable 0.00 Invoices Hook v2 # Written by brian! use WHMCS\Database\Capsule; function disable_00_invoices_v2($vars) { $validtemplates = array("Invoice Created","Invoice Payment Confirmation"); if (in_array($vars["messagename"], $validtemplates)) { $merge_fields = []; $invoicetotal = Capsule::table('tblinvoices')->where('id',$vars['relid'])->value('total'); if ($invoicetotal == "0.00") { $merge_fields['abortsend'] = true; return $merge_fields; } } } add_hook("EmailPreSend", 1, "disable_00_invoices_v2"); lol - Dennis beat me to it. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 25, 2019 Share Posted September 25, 2019 1 minute ago, brian! said: that's an old hook! 👴 And I can't imagine how it has ever worked since the if sentence doesn't have any brackets 😛 Would that have been working at some point? 0 Quote Link to comment Share on other sites More sharing options...
Bertie Posted September 25, 2019 Author Share Posted September 25, 2019 I think the hook was located on another website a while back - Thanks guys, I will give it a go! 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 25, 2019 Share Posted September 25, 2019 5 minutes ago, DennisMidjord said: And I can't imagine how it has ever worked since the if sentence doesn't have any brackets 😛 Would that have been working at some point? it must have - possibly it still would under PHP5.6 (haven't checked) - there are missing brackets in some of the reports IF statements and they still work... it doesn't look "right" though. 4 minutes ago, Bertie said: I think the hook was located on another website a while back - Thanks guys, I will give it a go! I remember it from a whmcsjet post back in 2012... though whether they wrote it or they found it somewhere, I don't know. 0 Quote Link to comment Share on other sites More sharing options...
Bertie Posted May 6, 2020 Author Share Posted May 6, 2020 (edited) Anything changed in the recent updates of WHMCS to stop this from working? Seems like the £0 email notification is being sent out. I have the following code: <?php # Disable 0.00 Invoices Hook v2 # Written by brian! use WHMCS\Database\Capsule; function disable_00_invoices_v2($vars) { $validtemplates = array("Invoice Created","Invoice Payment Confirmation"); if (in_array($vars["messagename"], $validtemplates)) { $merge_fields = []; $invoicetotal = Capsule::table('tblinvoices')->where('id',$vars['relid'])->value('total'); if ($invoicetotal == "0.00") { $merge_fields['abortsend'] = true; return $merge_fields; } } } add_hook("EmailPreSend", 1, "disable_00_invoices_v2"); Edited May 6, 2020 by Bertie 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 6, 2020 Share Posted May 6, 2020 16 minutes ago, Bertie said: Anything changed in the recent updates of WHMCS to stop this from working? not that i'm aware of. 😕 I just tried it on v7.10.1 with an existing 0.00 invoice in the admin area - with the hook disabled, the email was sent; with the hook enabled, it wasn't. it would be interesting to know under what conditions the hook doesn't appear to work. 0 Quote Link to comment Share on other sites More sharing options...
Bertie Posted May 7, 2020 Author Share Posted May 7, 2020 (edited) 21 hours ago, brian! said: not that i'm aware of. 😕 I just tried it on v7.10.1 with an existing 0.00 invoice in the admin area - with the hook disabled, the email was sent; with the hook enabled, it wasn't. it would be interesting to know under what conditions the hook doesn't appear to work. We have a hosting package that includes a free renewal and states that on the invoice the client gets. WHMCS raises the invoice for the package as normal but then it also raises an invoice just for the domain name renewal with £0 value. This £0 invoice is the one that still gets sent out via email by the looks of it. Looking at the activity log for "Email Sending Aborted by Hook". There is a lot of "Email Sending Aborted by Hook (Subject: Invoice Payment Confirmation)" and only a couple of "Email Sending Aborted by Hook (Subject: Customer Invoice)" every so often. This is using: 7.9.2 and not 7.10.1 but I can't see updating fixing it unless WHMCS did change something between those versions. Edited May 7, 2020 by Bertie 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 7, 2020 Share Posted May 7, 2020 24 minutes ago, Bertie said: The product is a hosting package that includes a free 1 year domain renewal. WHMCS generates an invoice with an actual £ value in it and then the next date, it generates a £0 invoice for the domain renewal. It's that £0 domain renewal invoice that still gets sent out via email. Looking at the activity log for "Email Sending Aborted by Hook". There is a lot of "Email Sending Aborted by Hook (Subject: Invoice Payment Confirmation)" and only a couple of "Email Sending Aborted by Hook (Subject: Customer Invoice)" every so often. quick thought - can you check that these 0.00 domain renewal invoices used the "Customer Invoice" email template and not the "Credit Card Customer Invoice" (which wouldn't trigger the hook) - hopefully the content of the two templates are different enough to be able to tell which was used. 27 minutes ago, Bertie said: This is using: 7.9.2 and not 7.10.1 but I can't see updating fixing it unless WHMCS did change something between those versions. I don't think so - I can test it on v7.9.2 once you rule out the CCCI email template being used. 0 Quote Link to comment Share on other sites More sharing options...
Bertie Posted May 7, 2020 Author Share Posted May 7, 2020 1 hour ago, brian! said: quick thought - can you check that these 0.00 domain renewal invoices used the "Customer Invoice" email template and not the "Credit Card Customer Invoice" (which wouldn't trigger the hook) - hopefully the content of the two templates are different enough to be able to tell which was used. I don't think so - I can test it on v7.9.2 once you rule out the CCCI email template being used. The two templates are the exact same content by the looks of it - Is there a way to find out which one was actually triggered? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 7, 2020 Share Posted May 7, 2020 9 minutes ago, Bertie said: The two templates are the exact same content by the looks of it - Is there a way to find out which one was actually triggered? interesting question - I don't know to be honest... i've always kept their content different in the devs, so never had reason to check. I could think of one possible way if you could resend them again, but if you could resend them again, you would already know which template you were using anyway. ☺️ I don't suppose you have a relevant 0.00 invoice on a test account that you can resend via the invoice page ? 0 Quote Link to comment Share on other sites More sharing options...
Bertie Posted May 7, 2020 Author Share Posted May 7, 2020 1 hour ago, brian! said: interesting question - I don't know to be honest... i've always kept their content different in the devs, so never had reason to check. I could think of one possible way if you could resend them again, but if you could resend them again, you would already know which template you were using anyway. ☺️ I don't suppose you have a relevant 0.00 invoice on a test account that you can resend via the invoice page ? I'm going to assume it may use the credit card one as when you try and re-send it using "Invoice Created" - A message pop ups saying it's been aborted by the hook. But credit card one sends just fine. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 7, 2020 Share Posted May 7, 2020 Just now, Bertie said: I'm going to assume it may use the credit card one as when you try and re-send it using "Invoice Created" - A message pop ups saying it's been aborted by the hook. But credit card one sends just fine. in that case... $validtemplates = array("Invoice Created","Invoice Payment Confirmation","Credit Card Invoice Created","Credit Card Payment Confirmation"); 1 Quote Link to comment Share on other sites More sharing options...
salva Posted March 14, 2023 Share Posted March 14, 2023 On 9/25/2019 at 11:05 AM, brian! said: that's an old hook! 👴 I think to rewrite it for Capsule, it should be... <?php # Disable 0.00 Invoices Hook v2 # Written by brian! use WHMCS\Database\Capsule; function disable_00_invoices_v2($vars) { $validtemplates = array("Invoice Created","Invoice Payment Confirmation"); if (in_array($vars["messagename"], $validtemplates)) { $merge_fields = []; $invoicetotal = Capsule::table('tblinvoices')->where('id',$vars['relid'])->value('total'); if ($invoicetotal == "0.00") { $merge_fields['abortsend'] = true; return $merge_fields; } } } add_hook("EmailPreSend", 1, "disable_00_invoices_v2"); lol - Dennis beat me to it. Hi, I'm a bit late to the conversation. I have a similar problem but my email template has name = "Order Confirmation" and is of type = "general", so $vars['ŕelid'] references the client ID, not the service ID. How can i make sure to select and check the invoice of the service (check that total=0.00) that triggered the Order Confirmation email, and doing it inside the EmailPreSend hook with only the client id? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.