Variant Quantity Updating Code - "Only X Left in stock"

Topic summary

A user is experiencing an issue with code that displays “X left in stock” messages for product variants. The current code only shows the correct inventory quantity after a page refresh, not when customers select different variants.

Current Problem:

  • Code uses product.selected_or_first_available_variant.inventory_quantity
  • Displays incorrect quantities when switching between variants (e.g., showing “2 left” for an out-of-stock variant)
  • Customers are leaving the site after clicking through variants

Attempted Solutions:

  • Two users suggested replacing the code with product.selected_variant.inventory_quantity instead
  • Neither solution worked—the code doesn’t recognize the new variable and shows no text or quantity

Current Status:

  • Unresolved—the original poster edited the code to only display on products without variants as a workaround
  • One user suggested a third-party Shopify app (sales stock counter) that displays variant-level inventory directly
  • The issue appears to be related to the Dawn theme and requires JavaScript or dynamic updating that the current Liquid code doesn’t provide
Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

I currently have this code on my products -

{% if product.selected_or_first_available_variant.inventory_quantity < 3 %}

{{ product.selected_or_first_available_variant.inventory_quantity }} left in stock


{% endif %}

But it only shows the correct variant quantity when you refresh the page. Is it possible to show the correct product quantity when selected? See the image where it shows the ‘ruled’ variant is out of stock, but the Graph has 2 left, and when you click back on ruled, it still shows ‘2 left in stock’. I have noticed a few customers clicking through the variants and leaving the site.

I tried tweaking it myself but out of my depth. I am using the Dawn theme.

thanks!

@izzy365

Please try this code

{% if product.selected_variant.inventory_quantity < 3 %}
  

    {{ product.selected_variant.inventory_quantity }} left in stock
  

{% endif %}

Thanks!

Hey @izzy365

Try to replace your code with the code mentioned below and check if this works for you

{% if product.selected_variant.inventory_quantity < 3 %}
  

    {{ product.selected_variant.inventory_quantity }} left in stock
  

{% endif %}

If I managed to help you then, don’t forget to Like it and Mark it as Solution!

Best Regards,
Moeed

Hi.

Thank you so much for your help.

Unfortunately, this didn’t work. It doesn’t show any text on the product now.

It doesn’t seem to recognise “product.selected_variant.inventory_quantity”

Hi.

Thank you so much for your help.

Unfortunately, this didn’t work. It doesn’t show the quantity.

Update, I edited the code so that it only shows up with stock quantities on products that do not have variants. If anyone ever solves this please let me know.

Hello, if you are okay with using 3rd party app for this use case, you can check this application. It directly shows the left in stock in variant level.