How can I convert options to variants in Liquid for product availability?

After playing around we’ve made a solution which works but isn’t the cleanest code:

{% unless product.has_only_default_variant %}
              {% for option in product.options_with_values %}
                
                {% assign option_position = forloop.index %}
                
              {% endfor %}
            {% else %}
              {% for option in product.options_with_values %}
                
                {% assign option_position = forloop.index %}
                
              {% endfor %}
          {% endunless %}

However: This will only work for products with one option field - not with multiple options!

1 Like