MBayDesign Posted June 11, 2020 Share Posted June 11, 2020 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 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 12, 2020 Share Posted June 12, 2020 <?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: 0 Quote Link to comment Share on other sites More sharing options...
MBayDesign Posted June 12, 2020 Author Share Posted June 12, 2020 Lifesaver! 🙂 Thank you very much! 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.