Include total discount on "new order" email notification

JMSarten
Shopify Partner
6 0 0

I'm working to edit the internal "new order" notification email that is sent from Shopify when an order is placed. Beneath the subtotal line I need to include a line displaying the total savings applied to the order. 

 

I've reviewed Shopify's guidelines on Liquid variables found here: https://help.shopify.com/en/manual/orders/notifications/email-variables#discounts and found that the discount_application.total_allocated_amount variable should accomplish what I'm needing. However when adding it in a table row, the "Discounts" title is displayed but the value is not (see screenshot below)

 

Screen Shot 2023-07-15 at 10.31.31 PM.png

 

Current code is below:

 

<tr class="subtotal-line">
  <td class="subtotal-line__title">
    <p>
      <span>Discounts</span>
    </p>
  </td>
  <td class="subtotal-line__value">
    <strong>{{ discount_application.total_allocated_amount | money }}</strong>
  </td>
</tr>

 

Any ideas on what I might be missing?

Reply 1 (1)

Liam
Shopify Staff
2731 302 783

Hi JMSarten,

 

You may need to wrap your code in a for loop that will check for all discounts (as there could be multiple). In the doc you've linked you'll see an example of this where there's the code for returning discount data is wrapped in:  

{% for discount_allocation in line.discount_allocations %} ... {% endfor %}

In your case you'll need to use something like:

{% for discount in order.discount_applications %}
<tr class="subtotal-line">
  <td class="subtotal-line__title">
    <p>
      <span>{{ discount.title }}</span>
    </p>
  </td>
  <td class="subtotal-line__value">
    <strong>{{ discount.total_allocated_amount | money }}</strong>
  </td>
</tr>
{% endfor %}

Try out this approach and let us know if it's not working for you.

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog