Jump to content

Hook triggers after invoice is sent - please HELP!


minadreapta

Recommended Posts

Hello,

i have this problem which i think appeared after the upgrade from WHMCS v7 to v8:

i have a hook at /includes/hooks/invoice_date.php that modifies the final invoice date to be the actual time of marking the invoice paid, instead of the proforma generation date:

<?php
function proformainvoicepaiddate($vars) {
$invoiceid=$vars["invoiceid"];

update_query("tblinvoices",array("date"=>"now()"),array("id"=>$invoiceid));
}
add_hook("InvoicePaid",0,"proformainvoicepaiddate","");
?>

The hook works but it's getting triggered after the PDF invoice email is sent to the client.

So the WHMCS sends the email to the client, then the hook runs. The client gets the invoice with the wrong date (the proforma first generation date) and only after this, the hook changes the date on the final invoice.
This way in WHMCS i get one date for the final invoice and the client receives an email with a different date for the same invoice. This is illegal in my country.

Can you please help me find a workaround for this, i mean getting the hook triggered before the email is sent to the customer?

I know now there is a hook-point called EmailPreSend that runs prior to any templated email being sent but i don't know how to implement it, i am not a PHP programmer.
https://developers.whmcs.com/hooks-reference/everything-else/#emailpresend

Any help here, please?

Thanks.

Link to comment
Share on other sites

Hello bro,

You can try using this hook here: https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaidpreemail
It will trigger once the Invoice is marked as Paid and before the email send.

Try this one:

<?php
function proformainvoicepaiddate($vars) {
	$invoiceid = $vars["invoiceid"];

	update_query("tblinvoices", array("date" => "now()"), array("id" => $invoiceid));
}

add_hook("InvoicePaidPreEmail", 0, "proformainvoicepaiddate","");
?>

 

Link to comment
Share on other sites

On 1/5/2022 at 1:49 PM, andrezzz said:

Hello bro,

You can try using this hook here: https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaidpreemail
It will trigger once the Invoice is marked as Paid and before the email send.

Try this one:


<?php
function proformainvoicepaiddate($vars) {
	$invoiceid = $vars["invoiceid"];

	update_query("tblinvoices", array("date" => "now()"), array("id" => $invoiceid));
}

add_hook("InvoicePaidPreEmail", 0, "proformainvoicepaiddate","");
?>

 

That worked.

Thanks Andrezzz!

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