Jump to content

External variable on invoice payment confirmation email


tuga

Recommended Posts

Hi,

My credit card provider uses random charge name statements and some clients dispute the payments because they don't recognize them. Long story short, I'd like to insert an external variable on the invoice payment confirmation email. Something like:

  • Request url
  • Get var
  • Insert var on email

Is this possible? if so, how can it be done?

Thank you.

Edited by tuga
Link to comment
Share on other sites

Hi tuga,

This would be possible with the EmailPreSend hook, you can simply merge your additional variable into the relevant email templates.

For example, say you wanted to add the variable $myCoolVariable, open email templates in WHMCS by going to System Settings > Email Templates and edit the following templates:

  • Invoice Payment Confirmation
  • Credit Card Payment Confirmation

Add the variable to the templates above in the format {$myCoolVariable}

Then create a new file in your /includes/hooks/ folder (e.g. addCustomVariableToInvoiceConfirmationEmail.php) with the following code:

<?php

function add_custom_variable_to_invoice_confirmation_email($vars) {

    $templates = [
        'Credit Card Payment Confirmation',
        'Invoice Payment Confirmation'
    ];


    $messageName = $vars['messagename'];
    $merge_fields = [];

    if (in_array($messageName, $templates)) {

         $merge_fields['myCoolVariable'] = 'This is my awesome and really cool variable!';

    }

    return $merge_fields;

}

add_hook('EmailPreSend', 1, 'add_custom_variable_to_invoice_confirmation_email');

 

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