Display message in order conf if any product contains a certain tag

New Member
2 0 0

Hi there,

 

I'm trying to add a special line into an intro paragraph of the Order Confirmation email if *any* product contained in the order has a specific tag. (It's something I only want showing up once if the tag appears on any product in the order, instead of looping with each line product in the order summary.)

 

And note: it's a product tag, not an order tag.

 

Would any of these achieve that?

 

{% if order.tags contains "pre-order" %}
Your order contains a pre-order item.
{% endif %}
{% for item in checkout.line_items %}
 {% if item.product.tags contains "pre-order" %}
Your order contains a pre-order item.
{% endif %}
{% endfor %}
0 Likes
Astronaut
1091 150 274

It looks like you don't have access to product tags in the notification template. A way that I can think to get around this is to make a variable inside of your order confirmation template that has all the skus of all the products you want to keep track of. So at the top of your order confirmation make a string containing the skus of the products you want to know about, then find your line items loop and check if the sku is in the string:

 

 

{% assign product_sku_array = "AED-992, OBR-919, LQL-331" %}

{% for line in subtotal_line_items %}

  {% if product_sku_array contains line.variant.sku %}
    //Your message here
  {% endif %}

{% endif %}

 

 

 

 

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
New Member
2 0 0

I've got this working actually, but it's repeating for every pre-order in the item. So, for instance, if my item contains 5 items and 2 are pre-orders, this is showing up twice.

 

{% for line in subtotal_line_items %}
{% if line.product.tags contains "pre-order" %}
Pre-order message
{% endif %}
{% endfor %}

Is there a way to not make it loop like that, only do it once for the whole order?

0 Likes
Astronaut
1091 150 274

You can break out of the loop with a counter:

{% assign count = 0 %}
{% for line in subtotal_line_items %}
  {% if line.product.tags contains "pre-order" and count < 1 %}
    {% assign count = count | plus: 1 %}
      Pre-order message
   {% elsif count == 1 %}
      {% break %}
   {% endif %}
{% endfor %}

 Give that a go.

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes