Inventory tracking on product page adjustment

Hi,

I’m currently using a inventory tracking code on my product pages so it shows how many items are left in stock, however for pre-orders, when an item gets purchase it becomes a negative number and subsequently shows -1 in stock. How would i change the code so that if the quantity remaining is a negative number, it shows 0 instead?

(The code i’m running for the inventory tracking is the same as on this page

https://ecomexperts.io/blogs/liquid-tutorial-shopify/show-the-number-of-products-left-in-stock-on-your-shopify-product-page)

Also, in the filter and sort section, when sorting by availability, it also shows items with no stock, but with the (continue selling when out of stock option) as “In stock”, Would that be able to be changed into the Out of Stock category instead?

Website is www.ffcollectibles.com.au if needed

Sorry, actually inventory tracking code is not the link above, its using this.

https://ed.codes/blogs/tutorials/display-variant-inventory-count-on-product-page-dawn-theme-no-app-shopify-2-0

If instead, when the “continue selling when out of stock” option is ticked, instead of displaying inventory level, how would i display text that says “pre-order now”

Hi @henrycui ,

  • With inventory tracking: I checked and it shows 0, did you change it?

  • With filter: It is still considered ‘In stock’ and this is Shopify’s default, you cannot edit it.

Hope it is clear to you.

Hi,

Sorry not sure if i made it clear before, i added an extra block in the product information area using the code from above link (https://ed.codes/blogs/tutorials/display-variant-inventory-count-on-product-page-dawn-theme-no-app-shopify-2-0)

However instead of showing 0 in stock for items with the “continue selling when out of stock” option ticked, i wanted it to show text that says “pre-order”

Hi @henrycui ,

You just need to change the code at step 2, it will work fine:

{%- when 'inventory_count' -%} 
   
    {% if product.selected_or_first_available_variant.inventory_quantity <= block.settings.show_inventory_threshold or block.settings.show_inventory_threshold == 0 %} 
      

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

 
    {% elsif product.selected_or_first_available_variant.inventory_quantity <= block.settings.show_inventory_threshold and product.selected_or_first_available_variant.inventory_management == 'shopify' %}
      

Pre-order

    {% endif %} 
  

Hope it helps!

Just tried it, seems to still be the same :sweat_smile: