Jump to content

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

 

 

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

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)
Link to comment
Share on other sites

  • 1 month later...

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

  • Thanks 1
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...