Heh. I figured it out but it ain’t pretty!
{% assign multipleAvailable = 0 %}
{% for variant in product.variants %}
{% if variant.available %}
{% if multipleAvailable == 0 %}
{% assign multipleAvailable = 1 %}
{% else %}
{% assign multipleAvailable = 2 %}
{% endif %}
{% endif %}
{% endfor %}
Basically I set a flag (multipleAvailable) to 0. Then I enter the variant loop. If a variant is available and it is the first time a variant has been detected as available, it sets the flag to 1. Then if it encounters any subsequent available variants, it sets the flag to 2.
Therefore, if the flag = 1 there is only 1 available variant, if flag = 2 then there are 2 or more available variants.
It’s not a ‘count’ but it’s enough for what I needed.
Yuk yuk yuk. Hope you can suggest something better Shopify!
I'm not sure what your use case was here, but this resolved my issue:
https://community.shopify.com/c/Shopify-Design/See-if-a-product-has-variants/td-p/414668
User | Count |
---|---|
547 | |
210 | |
127 | |
79 | |
46 |