Can liquid track changes in inventory levels?

Topic summary

Whether Liquid can detect a change in a product’s inventory state (e.g., from 0 to >0). Consensus: Liquid has no memory or built-in properties for “previous” inventory; it only exposes current values.

Key limits in Liquid:

  • Variant exposes inventory_quantity, incoming, and next_incoming_date; there is no previous or next_incoming_quantity field.
  • Therefore, you cannot compare past vs current inventory directly in Liquid.

Workarounds suggested:

  • Frontend logic: compare items in cart vs current availability using Liquid/JavaScript to show messages (common theme behavior).
  • Shopify Flow + metafields: create a variant metafield (e.g., inventory.prior_inventory_quantity) and use the Flow trigger “inventory-quantity-changed” to write the prior value (variable: inventoryQuantityPrior) to that metafield. Themes/notifications can then read it to conditionally message restocks. Multi-variant products may need additional logic/JS.
  • A Flow template (“Tag out of stock products for a single location only”) can be adapted to “update metafield (variant)” instead of tagging.

Notes:

  • An image and a small Liquid snippet were shared to illustrate the Flow setup and metafield access.

Status: No native Liquid solution; practical resolution is to use Shopify Flow/metafields or frontend logic. Users thanked contributors.

Summarized with AI on December 15. AI used: gpt-5.

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 !