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
Shopify Staff
2862 313 813
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