Jump to content

Access mail tpl variables


Linuc82

Recommended Posts

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.

Link to comment
Share on other sites

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 by LosBooom
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