How to check product tag match with array value

How to check product tag match with array value

abzalali
Shopify Partner
9 0 2

I want to check if any of my products match a given array value. 

Here's my product tag:

{% assign product_tags = product.tags | split: ',' %}

Here's my discount code:

{% assign discountCode = "50off, 100off, 150off, 200off, 250off, 300off, 350off, 400off, black_friday_2022" | split: ',' %}

What I have tried with:

{% for tag in product_tags %}
    {% if discountCode contains tag  %} 
         Extra in-Cart Discount
      {% endif %}
{% endfor %}

Any help would be much appreciated

Replies 2 (2)

ZenoPageBuilder
Shopify Partner
1052 203 225

You are doing the right way, but the code need some changes

1. Remove spaces between discount codes

 

{% assign discountCode = "50off,100off,150off,200off,250off,300off,350off,400off,black_friday_2022" | split: ',' %}

 

2. We should break the loop if the match tag is found

 

{% for tag in product_tags %}
    {% if discountCode contains tag  %} 
         Extra in-Cart Discount
         {% break %}
      {% endif %}
{% endfor %}

Hope that helps!

 

Zeno Page Builder - Build responsive & SEO-optimized Landing pages, Blog posts, Product pages and more...
Learn more at zenobuilder.com
wonena-dev
Shopify Partner
21 0 7

Apparently the product_tags isn't recognized by flow. 

 

CEOWonena_0-1725643406140.png

 

Building a Sustainable Marketplace from Scratch