I applied the suggested code on below link to display the variant inventory quantity on my product page. And that worked great!
Now I want to adjust the code to take it to the next level. I want to add the inventory quantity by location (We have multiple locations). To show like availability on location A is X and location B is Y.
Any chance someone worked on it before?
Unfortunately, this is not possible just by adding code to your product template. Liquid doesn't have access to location inventory levels (just the total), so unless that changes, there' no way to do that yet. You can look into apps that offer this functionality.
I found the following at the app store:
Can't vouch for any of those, because we've never used any, but they seem to have 14-day trials, so you can check them out.
In the documentation for variant.store_availabilities, it says "Returns an array of store_availability objects if variant.selected is true." For variant.selected to be true, the variant must be specified as a URL parameter. However, I'm still not able to get it to return anything, even with this in place.
The variant.store_availabilities only shows if a variant is stocked in a specific location (mostly used to determine if a product can be picked up from a location), it doesn't come with stock levels. There's an implementation example here: https://shopify.dev/tutorials/add-store-availability
Thanks @pvoulg. I don't need actual levels per location, just whether it is available at a location, but I still can't get it to return anything. I've seen that example implementation, which is not exactly what I'm trying to achieve. Essentially I just need to know, for each variant, if it is available at one of our two locations. Any idea on how to do this?
So, yeah, as far as I can tell, this seems to be a Liquid bug or error. Some have noted that pickup needs to be enabled for all locations for it to work, whereas others have said that this doesn't work even when they are enabled. I will investigate further and get back to you if I figure anything out.