skip to Main Content

I want to display discount codes in new order email notification template, using this code:

{% for discount in discounts %}
  {{ discount.code }} : {{ discount.savings | money_with_currency }}
{% endfor %}

It’s displaying the discount amount but not the discount code name/title. It’s returning blank even if the discount is manually entered in the back-end when creating an order.

How can I display discount codes no matter where it’s entered i.e in admin or checkout?

2

Answers


  1. In notifications you may access to discount_application object as explained here:
    https://shopify.dev/docs/themes/liquid/reference/objects/discount-application

    So (not tested), something like that might work:

    {% for discount_application in discount_applications %}
      {{ discount_application.title }} : {{ discount_application.value }}
    {% endfor %}
    

    HTH

    Login or Signup to reply.
  2. You can get it from your cookies:

      <div id="discount-message"></div>
      <script type="text/javascript">
        var codeCookieValue;
        var getCookie = function(name) {
          var value = "; " + document.cookie;
          var parts = value.split('; '+name+'=');
          if (parts.length == 2) return parts.pop().split(";").shift();
        };
        codeCookieValue = getCookie('discount_code');
      </script>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search