Custom Order Confirmation Email

Hi

I am requesting help with a custom order confirmation email update.Here are the requirements:

  1. Display custom HTML markup based on the product ID of the product purchased. For example, if the ProductID is 111, then display
    You have purchased product 111.
  2. If the order contains multiple purchases of a product, only display one instance of the HTML markup. In other words, if the order contains two productID 111 items, only show the ProductID 111 markup once.

I have successfully met requirement 1 through the following liquid code:

{% for line in subtotal_line_items %}

{% assign productID = line.product.id %}

{% case productID %}

{% when 111 %}

ProductID 111 markup goes here...

{% when 222 %}

ProductID 222 markup goes here...

{% when 333 %}

ProductID 333 markup goes here...

{% else %}

{% endcase %}

{% endfor %}

So far so good. But I am unable to meet requirement 2.

Specifically, I have added IF statements to only display the markup if it is the first. But this fails; specifically, no custom markup displays.

Here is the code that fails:

{% for line in subtotal_line_items %}

{% assign productID = line.product.id %}

{% case productID %}

{% when 111 %}

{% if productID.first == 111 %}

ProductID 111 markup goes here...

{% endif %}

{% when 222 %}

{% if productID.first == 222 %}

ProductID 222 markup goes here...

{% endif %}

{% when 333 %}

{% if productID.first == 333 %}

ProductID 333 markup goes here...

{% endif %}

{% else %}

{% endcase %}

{% endfor %}

Look forward to your suggestions.

Thanks in advance, and please let me know if you have any questions.

Hi @mharle

You need to use third variable, as this is happening when same product with different variant.
Try this code and let me know if that work for you

{% assign product_111_status = true %}
{% assign product_222_status = true %}
{% assign product_333_status = true %}
{% for line in subtotal_line_items %}

    {% assign productID = line.product.id %}
   

    {% case productID %}

        {% when 111 %}  
          {% if product_111_status %}
            ProductID 111 markup goes here...

            {% assign product_111_status = false %}
        {% endif %}
  
        {% when 222 %}
        {% if product_222_status %}
            ProductID 222 markup goes here...

        {% assign product_222_status = false %}
        {% endif %}
        {% when 333 %}       
         {% if product_333_status %}  
            ProductID 333 markup goes here...

           {% assign product_333_status = false %} 
{% endif %}
        {% else %}

            

    {% endcase %}   

{% endfor %}

@ankeshgupta

Ankesh - works perfectly. Thank you very much.