Linuc82 Posted October 16, 2022 Share Posted October 16, 2022 The "Order Confirmation" email template is a system default email template under "General Messages". I need to use the {$invoice_num} variable associated with the order in the "Order Confirmation" email template. However, it seems that {$invoice_num} cannot be accessed because it is available for "Invoice Messages" and not "General Messages". Any help appreciated. 0 Quote Link to comment Share on other sites More sharing options...
LosBooom Posted October 17, 2022 Share Posted October 17, 2022 (edited) I usually do it with https://developers.whmcs.com/hooks-reference/everything-else/#emailpresend File to add in includes/hooks <?php use WHMCS\Database\Capsule; add_hook('EmailPreSend', 3, function ($vars) { $order_id = $vars['mergefields']['order_id']; if ($vars['messagename'] == 'Order Confirmation' && !empty($order_id)) { $invoiceid = Capsule::table('tblorders')->select('invoiceid')->where('id', $order_id)->first()->invoiceid; if ($invoiceid) { $invoice_num = Capsule::table('tblinvoices')->select('invoicenum')->where('id', $invoiceid)->first()->invoicenum; if ($invoice_num) { return ['invoice_num' => $invoice_num]; } } } }); Inside "Order Confirmation" template use like : {if $invoice_num}Invoice num: {$invoice_num}{/if} I recommend checking it in a test environment before using it in production. Edited October 17, 2022 by LosBooom 0 Quote Link to comment Share on other sites More sharing options...
Linuc82 Posted October 18, 2022 Author Share Posted October 18, 2022 Fantastic, works! Many thanks. 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.