I want to display the actual number of units sold for a particular product where visitors can see that the product they are looking at was
Ordered by
x
customers
or
Sold
y
units tox
customers in 24 hours
I want to achieve this via Liquid.
If I can get the initial & adjusted inventory of a variant/product then I can subtract the current inventory from it and get a number. Note that Adjusted inventory is a variable that we will keep on changing manually.
Ex: Initial Inventory: 50
Adjusted (added more): 50
Current Inventory: 40
Which means that we’ve sold (initial+adjusted)-current
= 60 units.
Please help me achieve this via Liquid
only.
2
Answers
There is no native field for that on the product and variant object. However, you could use metafields to define your own field:
You could then increment the value of the respective metafield whenever an item is sold. Check out Shopify Webhooks to learn more about how you can "wait" for an order to happen.
You do want to use Metafields for this and you don’t need an App, but it would be all automatic if you did use an App. Basically, Liquid can render any value to the customer saved as a Metafield. So if you assigned a number to a product, like 60, the customer could read that if you wanted, as "60 units sold!". The problem with that is you would manually update that number for each sale. Clunky! With a simple few lines of code, an App could listen for orders, and automatically update those numbers, so over the long term, you really do nothing and yet your customers get updated sales numbers. Up to you. But nothing is standing in your way of doing this manually.