Jump to content

Promo merge field for invoices


Recommended Posts

I have found old questions basically asking the same  thing, but no responses. I have looked on available merge fields for all email templates and can't find anything related to promotional codes. I'm trying to figure out a way to do the following:

I want to conditionally add a promo code value to the invoice and/or receipt email template if a promo has been applied.  

Obviously incorrect, but e.g. -- 

{if {$promo}  eq "anyvalue"}
 PROMO APPLIED:  {$promo eq "value"}{/if}

Possible?

Thanks!

Debbie
 

Link to comment
Share on other sites

<?php

use WHMCS\Database\Capsule;

add_hook('EmailPreSend', 1, function($vars)
{
    if (in_array($vars['messagename'], array('Invoice Payment Confirmation')))
    {
        $promotions = Capsule::select(Capsule::raw('SELECT description FROM tblinvoiceitems WHERE invoiceid = "' . $vars['relid'] . '" AND type = "PromoHosting"'));

        foreach ($promotions as $v)
        {
            $merge_fields['assigned_promos'][] = $v->description;
        }

        return $merge_fields;
    }
});

Before WHMCS sends "Invoice Payment Confirmation" the hook looks for promo in invoice. If a promo is found then it assign the {$assigned_promos} array you can use in Setup > Email Templates > Invoice Payment Confirmation like follows:

{if $assigned_promos}
Promo below:
{foreach from=$assigned_promos item=promo}
{$promo}
{/foreach}
{/if}

And here is the result:

sample-291.png.4d6b019cc79913005d4062399431e11a.png

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