Some merchants like to track and show publicly the amount of items sold on a product page, not just the amount left in stock. This is not something that Shopify does by default but with the use of the Mighty Metafield, it's a simple addition. Let's look at how it's done...
Why would you want to do that?
That's a good question that I'm asking myself. This can be handy when you've got a limited edition product and you need to show both the starting quantity, and what's left - eg: "42 of 500 remaining". It's more than just informative, that kind of message can help add a sense of urgency to sale (and in turn increase conversions) since customers don't want to miss out.
When armed with remaining numbers you also appease the design gods and do cool things like adding stock bars, or colour coding the count (green for lots, red to low), etc. This post will just keep things easy and deal with just displaying the numbers without any fancy wrapper.
Now the logic here is simple:
- Add a metafield to a product with the starting stock count
- In Liquid, use some Math to find the difference between the starting amount and the current stock amount
- Show this number on the page.
- Profit. Maybe.
If you read the metafield link above you'll see that there's a format for how they are crafted. I'll be assuming that you will use the metafield settings noted below. You can change them to whatever you like, so no pressure to follow exactly.
Namespace: stock
Key: initial
Value: any number
Type: integer
Now let's jump to the Bulk Product editor with the metafields already loaded up ready go. If you're logged into your account you can click this magic link to shortcut you there. With luck you should be seeing something that looks like the image below. Unless you've done this part before the initial column should be blank (unlike mine).
Once you've added the initial starting count be sure to click the save button top right of screen. Nice work - the metafields are now added. Let's move onto the code that will show this on the product page.
Is there other ways to edit metafields?
There's a few ways, so use whatever works for you.
- ShopifyFD
- Shopify Bulk Editing page
- Metafield app of your choice.
If the products are already created I would suggest using the Shopify Bulk editor. It will let you power through all the products and quickly add the starting count. Besides, I talk about ShopifyFD way too much anyway so this gives us the chance to talk about something else.
What about products with multiple variants?
In this example we've really only talked about a product with the single variant. At some point I will (should) double back over this post and update it with some tips on handling the multiple variant methods.