Hello, I’m trying to put a code into a confirmation mail. Below the title of the product that is ordered it should show the SKU, but only for certain products with certain tags (men, women and unisex)
So this is what I wrote:
{% if product.tag contains 'men, women, unisex' %}
SKU: {{ line.variant.sku }}
{% endif %}
However, it doesn’t work.
Does anyone know what I’m doing wrong?
Kind regards,
Thomas
This {% if product.tag contains ‘men, women, unisex’ %} will only try to match a tag against that singular product.tag with the exact text of “men, women, unisex” which isn’t possible as commas are disallowed within a tags.
If “men, women, unisex” is mean to be individual tags then you need to match each individual tag.
Noting inconsistent use of uppercase/lowercase etc can cause inconsistent results.
And that “men” is ambiguous as it will match the text in both “men” and “women” so you may need to do exact string comparisons for each tag instead of using contains.
{% assign normalized_product_tag = product.tag | downcase %}
{% if normalized_product_tag contains ‘men’ or contains ‘women’ or contains ‘unisex’ %}
If your not looping over product.tags (plural) instead of product.tag (singular) you need to use product.tags
{% assign normalized_product_tags = product.tags | join:", " | downcase %}
{% if normalized_product_tags contains ‘men’ or contains ‘women’ or contains ‘unisex’ %}