Can liquid track changes in inventory levels?

Can liquid be used to identify when inventory levels have changed?

For example:
if inventory was <= 0 and is now > 0

I’d like to use this logic to display certain messages based on the differences between current and previous inventory status

HI @The-Gift-Shop
Of course you can custom message base on inventory.
To do that, you need to add some custom code for your theme. If you don’t know about the code,
I think you need to hire an expert, they will help you make that.

No, liquid doesn’t have a “detection”/memory like this.

No does shopify have any exposed properties for frontend usage relating to old or new inventory states, only the current inventory quantity.

Unfortunately there aren’t even properties you can statically compare to if inventory transfers were being used.

https://shopify.dev/api/liquid/objects/variant#variant-inventory_quantity

There’s incoming and incoming_date but NO next_incoming_quantity

https://shopify.dev/api/liquid/objects/variant#variant-incoming

https://shopify.dev/api/liquid/objects/variant#variant-next_incoming_date

Frontend cart quantities

The closest you can achieve for the frontend is comparing how many items are in a users cart and the quantity available or if the item is not available. Either through liquid or in combination with javascript, most themes have a “all items are in your cart” behavior often using javascript that can be used as a jumping off point for such logic.

Shopify Flow metafields

Another approach is eligible stores using the free shopify-flow app.

Since there is no native frontend property for the previous inventory quantity of variants merchants could create one using metafield definitions(mfdf) then use shopify flow to update the mfdfs value to the current-quantity minus the orders-quantity.

Create a variant metafield, optionally make unique ones per locations , etc.

Namespace: inventory

Key: prior_inventory_quantity

https://help.shopify.com/en/manual/shopify-flow/reference/triggers/inventory-quantity-changed

In the flow scripts value use {{inventoryQuantityPrior}} that’s a variable made available by the trigger inventory-quantity-changed. not the value when creating the mfdf

Figure - shopify flow setup to update the value of variant mfdf inventory.inventoryQuantityPrior

In a themes or notifications,etc use logic similar to the following to access this mfdf for a product with a single variant in liquid.

{%- assign priorQuantity = product.first_available_variant
.metafields.inventory.inventoryQuantityPrior -%}

Products with multiple variants will need more specific logic and possibly supporting javascript.

1 Like

Thanks for taking the time to reply, that detailed info is helpful.

Thanks for this post. It’s very useful.
Inside Flow there’s a template called: “Tag out of stock products for a single location only” , and it just needs to be adjusted to change the “add tag” to “update metafield variant”.

Thanks !