Jump to content

Hook to disable invoices with total 0.00


J-B

Recommended Posts

Hi, 

I have a hook (its not from me) that disable sending 0.00 invoices.

<?php
use Illuminate\Database\Capsule\Manager as Capsule;
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
 $data = Capsule::table('tblinvoices')->where('id',$relid)->first();
 //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");
?>

This hook works great, but it disable invoice that is paid via credit too.

I have try ...

if (isset($data->total) && $data->total == '0.00') && (isset($data->credit) && $data->credit == '0.00')

But this code isnt working. 

Anyone a idea how I can disable only 0.00 total invoices and not invoices that is paid via credit?

Link to comment
Share on other sites

On 11/22/2018 at 3:59 PM, Kian said:

Your condition is wrong. This one should work.


if (isset($data->total) && $data->total == '0.00' && $data->credit != '0.00')

 

This code is not working too. Zero Invoices is sending again to the customers. 

 

Any other solution?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated