How to remove the sold out variants from a product?

Highlighted
New Member
3 0 2

Hello,

 

I'm using Prestige theme and I'm struggling to remove the sold out variants for a week. I tried the link from shopify but didn't work in my case, I tried a lot of variants out there to make my code work but didn't work.

 

Because the code is big I posted it here.

 

I'm thinking of an easy way to that, like adding a class to the variant list if the condition is true and to hide the specific variant.

 

{% for variant in product.variants %}{% if variant.inventory_quantity ==0 %}class{% endif %}{% endfor %}

And I applied in my case.

 

<li class="HorizontalList__Item {% for variant in product.variants %}{% if variant.inventory_quantity ==0 %}class{% endif %}{% endfor %}">

But the problem is that my hole code looks like this:

 

{%- for value in option.values -%}
<li class="HorizontalList__Item {% for variant in product.variants %}{{variant.inventory_quantity}}{% endfor %}"> <input id="option-{{ section.id }}-{{ forloop.parentloop.index0 }}-{{ forloop.index0 }}" class="SizeSwatch__Radio" type="radio" name="option-{{ forloop.parentloop.index0 }}" value="{{ value | escape }}" {% if value == option.selected_value %}checked="checked"{% endif %} data-option-position="{{ option.position }}"> <label for="option-{{ section.id }}-{{ forloop.parentloop.index0 }}-{{ forloop.index0 }}" class="SizeSwatch">{{ value }}</label> </li> {%- endfor -%}

And because of the {%- for value in option.values -%} it just adds the class to all variant lists.

 

I did some debugging to see what returns, I did it with 

<li class="HorizontalList__Item {% for variant in product.variants %}{{variant.inventory_quantity}}{% endfor %}">

And it shows all my variant quantities at once in my case 014673

 

Live example here 

 

Also I tried to check if the option is disabled to just hide the label and didn't work.

 

This is the peace where I check if the variant it's not available, just disable it.

 

<select id="product-select-{{ product.id }}" name="id" title="Variant">
{%- for variant in product.variants -%}
<option {% if variant == selected_variant %}selected="selected"{% endif %} {% unless variant.available %}disabled="disabled"{% endunless %} value="{{ variant.id }}" data-sku="{{ variant.sku }}">{{ variant.title }} - {{ variant.price | money }}</option>
{%- endfor -%}
</select>

Can someone help me?

0 Likes
Highlighted
New Member
3 0 2

I managed to make it work. 

2 Likes
Highlighted
New Member
1 0 0

How did you solve this? Using the same Prestige theme.. Thanks!

0 Likes
Highlighted
New Member
1 0 0

Can you please let us know how?

0 Likes
Highlighted
New Member
1 0 0

Can you please post your solution?

0 Likes