Is there an easier way to achieve this?
Perhaps using a |filter
function?
{% set variantIds = [] %}
{% for variant in product.variants %}
{% set variantId = variant.id %}
{% set variantIds = variantIds|merge([variant.id]) %}
{% endfor %}
{% if wheelSpacer in variantIds %}
this spacer
{% endif %}