All things Shopify and commerce
Hi
I am requesting help with a custom order confirmation email update.Here are the requirements:
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.
Solved! Go to the solution
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 %}
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 %}
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025