Answers.Body: <p>This should filter the variants by their enabled status:</p>
  
  <pre><code>{% set product = craft.commerce.products.id(productId).first() %}
  
  {% for variant in product.variants if variant.enabled %}
      {{ variant.id }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T00:31:13.633Z
Answers.Text: It's always so simple, I feel so dumb for not even trying that! :)
Answers.UserDisplayName: Anders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T00:36:26.493Z
Answers.Text: On the other hand, you would think a disabled variant would be hidden by default unless included through templating.
Answers.UserDisplayName: Anders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-09T15:50:08.633Z
Answers.Text: I agree; you would think that `product.variants` would only return enabled products. How would you test to see if a product has enabled variants? Would you need to loop through and create a new array with only enabled variants? Or is there some property to access only enabled variants.
Answers.UserDisplayName: Trevor Davis
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-10T09:22:47.597Z
Answers.Text: To get only enabled variants of a product you can do it like this: 
  
       `{% set variants = craft.commerce.variants({
                                      product: product,
                                      enabled: true
                                  }) %}`
Answers.UserDisplayName: Andreas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-06T19:20:46.633Z
Answers.LastActivityDate: 2017-07-06T19:20:46.633Z
Answers.UserDisplayName: Brad Bell
Body: <p>Disabling a product variant doesn't remove it from a <code>{% for purchasable in product.variants %}</code> loop I have set up. It still renders an image associated with it, as well as a color swatch. Essentially not disabling it at all.</p>
  
  <p><code>{% for purchasable in product.variants if purchasable.status('live') %}</code> isn't working either, which I assume is only applicable to the product model.</p>
  
  <p>Any ideas?</p>
  
Tags: <templating><plugin-craftcommerce>
Title: Disabled product variant still shows in {% for %} loop
ThreadText: # Disabled product variant still shows in {% for %} loop
  
  (Asked by: username_0 on 2017-07-06)
  
  Disabling a product variant doesn't remove it from a `{% for purchasable in product.variants %}` loop I have set up. It still renders an image associated with it, as well as a color swatch. Essentially not disabling it at all.
  
  `{% for purchasable in product.variants if purchasable.status('live') %}` isn't working either, which I assume is only applicable to the product model.
  
  Any ideas?
  
  **Tags:** templating, plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-06. Score: 2 | Accepted answer
  
  This should filter the variants by their enabled status:
  
  ```
  {% set product = craft.commerce.products.id(productId).first() %}
  
  {% for variant in product.variants if variant.enabled %}
      {{ variant.id }}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: It's always so simple, I feel so dumb for not even trying that! :)  
  > **username_0**: On the other hand, you would think a disabled variant would be hidden by default unless included through templating.  
  > **username_2**: I agree; you would think that `product.variants` would only return enabled products. How would you test to see if a product has enabled variants? Would you need to loop through and create a new array with only enabled variants? Or is there some property to access only enabled variants.  
  > **username_3**: To get only enabled variants of a product you can do it like this:        `{% set variants = craft.commerce.variants({                                     product: product,                                     enabled: true                                 }) %}`  
  
  ---
  
  