Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Can I check if a product has tracked inventory with liquid?

Can I check if a product has tracked inventory with liquid?

grimworld
Shopify Partner
19 0 4

For a theme feature I'm developing, I'm checking if a product is sold out, low on stock, or is a 'preorder'.

 

Is there any way to check if the merchant unchecked the "Track Inventory" box in the product's settings?

 

For example:

{% if product_inventory.tracked = false %}

 

Let me know any clever workarounds!

 

Reply 1 (1)

Liam
Community Manager
3108 342 884
Hi Grimworld,
 
Unfortunately there isn't a direct way to check if the "Track Inventory" box is unchecked for a product using Shopify's Liquid code. The `product.inventory_management` object can tell you if inventory is managed by Shopify or not, but it does not specifically tell you if the merchant has manually unchecked the "Track Inventory" box.
 
However, you can possibly infer this by checking the `product.inventory_quantity` and `product.inventory_policy` objects. If `product.inventory_policy` is set to 'deny' (which means customers cannot purchase the product if it's out of stock) and `product.inventory_quantity` is greater than 0 (which indicates that the product is in stock), then it could imply that the "Track Inventory" box is checked. If `product.inventory_quantity` is 0 or less and `product.inventory_policy` is set to 'continue' (which means customers can still purchase the product even if it's out of stock), then it could imply that the "Track Inventory" box is unchecked - but this wouldn't be 100% accurate, so it depends on how critical the accuracy is for your use case. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog