Custom Order Confirmation Email

Solved

Custom Order Confirmation Email

mharle
Visitor
2 0 1

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
    <div>You have purchased product 111.</div>
  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 %}  

            <div>ProductID 111 markup goes here...</div>

        {% when 222 %}

            <div>ProductID 222 markup goes here...</div>

        {% when 333 %}       

            <div>ProductID 333 markup goes here...</div>

        {% else %}

            <span></span>

    {% 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 %}

            <div>ProductID 111 markup goes here...</div>

            {% endif %}

        {% when 222 %}

            {% if productID.first == 222 %}

            <div>ProductID 222 markup goes here...</div>

            {% endif %}

        {% when 333 %} 

            {% if productID.first == 333 %}      

            <div>ProductID 333 markup goes here...</div>

            {% endif %}

        {% else %}

            <span></span>

    {% endcase %}   

{% endfor %}

 

Look forward to your suggestions.

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

Accepted Solution (1)

ankeshgupta
Shopify Partner
41 9 4

This is an accepted solution.

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 %}
            <div>ProductID 111 markup goes here...</div>
            {% assign product_111_status = false %}
        {% endif %}
  
        {% when 222 %}
        {% if product_222_status %}
            <div>ProductID 222 markup goes here...</div>
        {% assign product_222_status = false %}
        {% endif %}
        {% when 333 %}       
         {% if product_333_status %}  
            <div>ProductID 333 markup goes here...</div>
           {% assign product_333_status = false %} 
{% endif %}
        {% else %}

            <span></span>

    {% endcase %}   

{% endfor %}

 

Ankesh Gupta | Shopify Theme Developer
- Was my reply helpful? Click Like or Accept solution to let me know!
Want a skilled Shopify developer? Reach out at
ankeshgupta0205@gmail.com

View solution in original post

Replies 2 (2)

ankeshgupta
Shopify Partner
41 9 4

This is an accepted solution.

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 %}
            <div>ProductID 111 markup goes here...</div>
            {% assign product_111_status = false %}
        {% endif %}
  
        {% when 222 %}
        {% if product_222_status %}
            <div>ProductID 222 markup goes here...</div>
        {% assign product_222_status = false %}
        {% endif %}
        {% when 333 %}       
         {% if product_333_status %}  
            <div>ProductID 333 markup goes here...</div>
           {% assign product_333_status = false %} 
{% endif %}
        {% else %}

            <span></span>

    {% endcase %}   

{% endfor %}

 

Ankesh Gupta | Shopify Theme Developer
- Was my reply helpful? Click Like or Accept solution to let me know!
Want a skilled Shopify developer? Reach out at
ankeshgupta0205@gmail.com
mharle
Visitor
2 0 1

@ankeshgupta 

Ankesh - works perfectly. Thank you very much.