Liquid OR connector not working / IF product.id == x OR y OR z

Hello shopify community,

Our shop offers individual products, including packages. We would like to add information under the heading title of the packages whether it is a package for 30 days or 60 days. That’s why I wrote the code, which first looks at whether the product is a package, and if yes, it continues to read specific product IDs. Then it should display specific information based on the product.id.

The code is following:

{% if product.tags contains 'packages' %}
        
        {% if product.id == 6986254057681 or 6986365075665 or 6986367402193 %}30 days
        {% elsif product.id == 6986366845137 or 6986369990865 or 6986370285777 or 6986371203281 %}60 days
        {% endif %}
        

      {% endif %}

The problem is that this code does not work. As soon as I define the condition or, the code stops working and does not display anything. Info message “30 days” must be assigned to multiple products, not just one. Therefore we need the condition or. What am I doing wrong and why doesn’t it work?

Thanks for your help.

Best regards

Michal

Hi @michalc524 ,

Please change code:

{% if product.tags contains 'packages' %}
                  
                    {% if product.id == 6986254057681 or product.id == 6986365075665 or product.id == 6986367402193 %}
                      30 days
                    {% elsif product.id == 6986366845137 or product.id == 6986369990865 or product.id == 6986370285777 or product.id == 6986371203281 %}
                      60 days
                    {% endif %}
                  

                {% endif %}

Or you can also add a tag directly to the product, for example, packages_30 for 30 days and packages_60 for 60 days and change the code as follows, it will be much easier to manage the product.

{% if product.tags contains 'packages_30' or product.tags contains 'packages_60' %}
                  
                    {% if product.tags contains 'packages_30' %}
                      30 days
                    {% elsif product.tags contains 'packages_60' %}
                      60 days
                    {% endif %}
                  

                {% endif %}

Hope it helps!

Hi LitExtension,

Yup it helped, it works! I should have defined product.id for every single condition. Your idea with tags is great, but we need to make single-product based customizations. Therefore is it necessary to use the product.id - adding product.tags for every product would be the same.

Best regards,

Michal