Shopify Inventory Text

43 views Asked by At

I am trying to get our website to display the text "Low stock. Order yours now" if the inventory of the product in question is less than 3.

I currently have the following code on the product-addcart.liquid section:

` {% if product.available %}

        <div class="remaining">
          <span class="variant-inventory">{{ current_variant.inventory_quantity }} Low stock. Order yours now.</span>
        </div>`

I tried edited the code to the code mentioned above. However, the text still says "2 pieces left! Order yours now." as seen here:

https://shop.abadia.me/collections/dresses/products/tube-gathering-dress

I don't have much experience with Shopify (or any) coding. Any help would be really appreciated. Thank you!

1

There are 1 answers

0
St3ph3n92 On

If you're trying to display a message when a variant is below a certain threshold, you should use an if statement. That will allow you to check if a condition is true (in this case if the variant inventory is less than 3), then you can output a message. Here's how your updated code would look:

{% if current_variant.inventory_quantity < 3 %}
<div class="remaining">
  <span class="variant-inventory">Low stock. Order yours now.</span>
</div>
{% endif %}

That said, this code will only display the message for the initial variants shown. You will need to udpate your JavaScript code so that it displays each time a new variant is selected.

I recommend asking these Shopify "how to" questions in the Shopify community forums since it is more focused. Here's a thread where a similar question has already been asked: https://community.shopify.com/c/technical-q-a/variant-inventory-quantity-and-variant-available-do-not-get/m-p/1396700