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

Highlighted
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
Highlighted
Shopify Partner
1445 195 523

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 my solution helped you, please like and accept as solution!
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
Highlighted
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
Highlighted
Shopify Partner
1445 195 523

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 my solution helped you, please like and accept as solution!
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
Highlighted
New Member
1 0 0

This solution was amazing - I was so surprised to find a thread regarding this. Now I have a question to expand on that...

Is there a way to have multiple counters going?

I have pre-order items, but I also have a notice that's posted if someone orders Product Type A and a different notice if someone orders Product Type B.

 

So three different messages.. Preorder, Product Type A, Product Type B. Each has its own message that is supposed to display if someone orders that type of item, but I don't want multiple copies of each message to show if someone orders say ...

 

2x Preorder

1x Product Type A

3x Product Type B

 

Lastly.. is there a way to have two different sections? I display the Preorder notice in a separate part of the email than the notices for Product Type A and Product Type B.

Any help would be greatly appreciated!

0 Likes