To clarify; if I have a disabled variant, and I'm looping through categories (colors) on each product like {% for variantColor in variantColors %}...{% endfor %} which makes it still show up in the list of colors.

Is there a way to, in that for loop, check if the variant it's connected to is enabled/disabled and then disregard, similar to {% for variant in variants if variant.enabled %}?

  • Just wanted to mention that I solved this within the module I've built to handle product types with categories, but would be great to know how to do this in Twig as opposed to PHP.
    – Anders
    Jun 25, 2019 at 4:09

1 Answer 1


yes, you could filter the variants for the status enabled to output only the enabled variants of the product.

 {% set products = craft.products.all() %}
 {% for product in products %}
     {{ product.title }} <br>
     {% set variants = product.variants|filterByValue('enabled', "1") %}
     {%- for purchasable in variants -%}
          {{ purchasable.id }} - {{ purchasable.description }} - {{ purchasable.price }}<br>
     {%- endfor -%}
 {% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.