How can I display out of stock text for product variants?

How can I display out of stock text for product variants?

Hannibal_Herman
Shopify Partner
4 0 0

Hi everyone,

 

I'm trying to display "In stock" and "Out of stock" on my product page with custom liquid. So when a customer selects a variant inside the product, it checks if the variant is in stock or not, and shows the relevant text. I have tried this, but it doesn't work, any ideas?

 

{% if variant.inventory_quantity < 1  %}
<p>In stock </p>
{% else %}
<p>Out of stock </p>
{% endif %}

 

Anyone knows what i do wrong?

Replies 7 (7)

SmallTask
Shopify Partner
973 41 55

Hi @Hannibal_Herman , 

 

Go to Online Store -> Themes -> Edit code -> Sections -> product-template.liquid and paste this code whereever you want to set.

 

{% if product.selected_or_first_available_variant.available == true %}
    <p>In Stock</p>
{% else %}
<p>Out of stock</p>
{% endif %}
banned
Hannibal_Herman
Shopify Partner
4 0 0

Hi Smalltask,

Thanks for the response, but it doesn't work.  ;(
You can still buy if it's out of stock, so everyone is available. Is there a way so if there is min 1 in stock it says "in stock" and if there is 0 it says "Out of stock"?

amorlett
Shopify Partner
186 12 34

try same thing but

 {%- if variant.available == false %} -  out of stock {% endif %}
Hannibal_Herman
Shopify Partner
4 0 0

Doesn't work ;/

amorlett
Shopify Partner
186 12 34

you are most likely pasting the code into the wrong place then  a good way to check is same code but put <h1> testing</h1> see where it shows up

Hannibal_Herman
Shopify Partner
4 0 0

I'm pasting the code correctly, just tried the <h1> testing</h1> and it shows up the right place.

 

But if i copy this code =
{%- if variant.available == false %} - out of stock {% endif %}

Nothing shows up ;/
My website is www.rios1931.dk

lynth
Shopify Partner
202 11 33

The problem might be in the way of implementation. You change your variant without page reload, because it's dynamic and liquid code is not updated. It should be done with JavaScript, not Liquid.

If my tips are useful, just mark it as the solution. Cheers!
Feeling grateful? Buy me a coffee!