Why does inventory code display out of stock for 10+ units?

Hello guys,

I’ve been banging my head against the wall trying to figure this one out, hopefully someone has some idea of what is going on.

Basically, on one of our client sites we have code that does the following:

  • When a product variant is in stock, it displays a message saying product is in stock

  • When the variant is out of stock, it displays a message saying out of stock

The code seems to work great, UNTIL one variant has 10 units of inventory or higher. Then the code displays as out of stock even though there is clearly inventory in stock.

Once the variant inventory is reduced to between 1-9, the message displays correctly that it is in stock.

Does anyone have any ideas why this could be happening?

Here is the code we’re using:

{%- if product.selected_or_first_available_variant.available == false -%}

In stock - Ships within 1-2 business days
3-4 week lead time

{%- else -%}

In stock - Ships within 1-2 business days
3-4 week lead time

{%- endif -%}

And in the CSS:

.show{display:block !important;}

.hide{display:none !important;}

I have tried a bunch of different things and none of them seemed to work.

Any suggestions would be greatly appreciated.

Thank you!

1 Like

Hi @srdjank ,

You cannot use liquid to function as you wanted. You have to use Javascript and check the product variant object.

This code is only checking the first variant. If the customer, change the variant, then this is not going to change

{%- if product.selected_or_first_available_variant.available == false -%}

Hi @srdjank ,

I know that you would like to create this feature with coding, however, if you want to use one app that does not require any coding skills to implement this feature, you can check Hey! Sold & Low Stock Counter