Shopify themes, liquid, logos, and UX
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
Solved! Go to the solution
This is an accepted solution.
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
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.
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.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
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.
This is an accepted solution.
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
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.
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.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
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 !
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024