If Statement to show/hide button ONLY if ALL variants are Sold Out.

Solved
Highlighted
Tourist
6 1 0
On my site, I recently added a Back in Stock button. I want my “notify when available button” to show ONLY when ALL variants are sold out. I’m having an issue with my if statement. The button shows even when a single variant is sold out vs when ALL variants are sold out. Can someone help me update the code below.

Here is the code I use.

{% assign variantQuantity = product.variants | map: 'inventory_quantity' | sort %}
{% if variantQuantity[0] < 1 %}
<button id="BIS_trigger">Notify Me When Back in Stock</button>
{% else %}

{% endif %}
0 Likes
Highlighted
Excursionist
629 110 323

Use this code.

{%if product.available %}
   <button id="BIS_trigger">Notify Me When Back in Stock</button>
{% endif %}

-like my answer and mark it as an accepted solution

 

thank you

0 Likes
Highlighted

Success.

Tourist
6 1 0

Thanks for the suggestion, using if in your code actually doesn't work but with a bit of research, i found that unless does.

 

        {%unless product.available %}
           <button id="BIS_trigger">Notify Me When Back in Stock</button>
        {% endunless %}

Thank you so much!

0 Likes