Jump to content
ktraving

Email templates with conditional content (only show discount if greater than 0)

Recommended Posts

After having completed a few test orders on our web shop I stumbled across a few things that needs changing, before we can go live.

 

One of them is the order confirmation email, in which discounts and gift wrapping costs are shown regardless of the amount.

 

I would like them to be shown ONLY if they are greater than 0.

 

Can I change this in the back office under localization->translations->email-translations ? It seems to be limited to basic HTML / TinyMCE.

 

I have also had a look in the mails folder, and here the order-conf.html seems to be the place to go, but its HTML, and thus conditional coding doesn't seem possible?

 

Ideas and suggestions are greatly appreciated.

 

Cheers, K

 

 

Share this post


Link to post
Share on other sites

I'm searching too where I can insert a condition in the email order template

Share this post


Link to post
Share on other sites

After having completed a few test orders on our web shop I stumbled across a few things that needs changing, before we can go live.

 

One of them is the order confirmation email, in which discounts and gift wrapping costs are shown regardless of the amount.

 

 

 

 

Apologies for highjacking your post but you mention the display of discount figures. Are you able to show discount amounts correctly in your order confirmation emails? For me, it's always a '0'. Our discounts are driven by the customer group. In the order confirmation, it shows the line item price already including the discount and then a 0 isn the discount line. I was just wondering wether it is working correctly for you.

 

Thanks!!

Edited by intandem (see edit history)

Share this post


Link to post
Share on other sites

As far as i know, all payment modules extends PaymentModule class, so in validateOrder() you could add new fields in $data, which is an array used near Mail::Send, over line 705.

 

So you could create a string variable like:

$discount_html=($order->total_discounts)?'<tr class="conf_body">
                            <td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0">
                                <table class="table" style="width:100%;border-collapse:collapse">
                                    <tr>
                                        <td width="10" style="color:#333;padding:0"> </td>
                                        <td align="right" style="color:#333;padding:0">
                                            <font size="2" face="Open-sans, sans-serif" color="#555454">
                                                <strong>Descuentos</strong>
                                            </font>
                                        </td>
                                        <td width="10" style="color:#333;padding:0"> </td>
                                    </tr>
                                </table>
                            </td>
                            <td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0">
                                <table class="table" style="width:100%;border-collapse:collapse">
                                    <tr>
                                        <td width="10" style="color:#333;padding:0"> </td>
                                        <td align="right" style="color:#333;padding:0">
                                            <font size="2" face="Open-sans, sans-serif" color="#555454">
                                                '.Tools::displayPrice($order->total_discounts, $this->context->currency, false).'
                                            </font>
                                        </td>
                                        <td width="10" style="color:#333;padding:0"> </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>':'';

and inside $data

'{discount_html}' =>  $discount_html,

finally if you go to your email html template, remove da '<tr>' that correspond to discount (line 152 in order_conf.html) and add '{discount_html}', it will only show discounts when its greater than 0

Share this post


Link to post
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.   Restore formatting

  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.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More