Add code to a specific product and if statements in Shopify

Posted on: July 5th, 2022
By: Tadeo Lemus

{% if product.handle == 'product-url' %}
<!-- add your code here -->
{% endif %}
{% if product.handle == 'product-url' and product.handle == 'product-another-url' %}

{% if product.handle == 'product-url' or product.handle == 'product-another-url' %}

{% if product.type != "typeA" and product.type != "typeB" and product.type != "typeC" %}

You would use “and” to make it so that it matches both conditions (in which case you can’t set both conditions to be two pages since a user can’t be on two pages within the same tab) and use “or” to make it so it needs to match either condition.

You don’t need to add the URL with the /products/ portion of it, just add the one from the product itself.

You can also assign different templates and assign those products to those templates but using the code above is much simpler.

I found the answer in this Shopify support article.

Have any questions or comments? Write them below!

Leave a Reply

Your email address will not be published. Required fields are marked *