How can I show product inventory location on my website's product page?

How can I show product inventory location on my website's product page?

Alocard
Shopify Partner
29 4 6

Hey,

I would like to display my products' inventory location on my website's product page. The product's inventory location can be found under the according product:

Alocard_1-1653307723828.png

 

I have tried editing the code in the product.liquid file, like this:

<!-- some code -->

{% assign availabilities_array = product.selected_or_first_available_variant.store_availabilities %}
{% for availability in availabilities_array %}
   {% assign location = availability.location %}
   <p>{{location.name}}</p>
{% endfor %}

<!-- more code -->

 

Unfortunately, the availabilities_array is always empty.
I am looking forward for your help and thank you in advance.

Best regards

Replies 4 (4)

Alan15
Shopify Partner
148 27 72

Is it a case that you need to enable local pickup? Your code seems to work when it's enabled. There's something here about the store_availability object: https://shopify.dev/api/liquid/objects/storeavailability

"The store_availability object is defined only if one or more locations has local pickup enabled."

Need more help? Contact me here

Josh18
Shopify Partner
9 0 4

I'm having a similar problem. The "store_availabilities" liquid object is always empty. I have tried enabling/re-enabling Local Pickup on the one location that we have but the backend still returns nothing when trying to access it via liquid. Strangely enough, I am able to access the same information via the Storefront API.

 

I also tried the exact same theme code on another development store with Local Pickup enabled and everything works fine. I'm convinced there is a backend issue here but Shopify support keeps directing me to contact a Shopify Expert to have a look at the theme code.

 

Have you made any progress with this?

Alocard
Shopify Partner
29 4 6

Hello @Josh18 ,
I am very sure that there is a problem with Shopify's backend.
Like you, I have enabled the "local pickup" option. I have checked if my location has the needed product variant in stock. I have read the Shopify Devs. But nothing seems to work.
The variant.store_availabilities array is always empty.
I have stopped working on this problem.

Best regards

Alocard

Keegan10
Shopify Partner
10 0 0

Hi there, 

 

Perhaps our app may help solve this for you, so I wanted to share. 

https://apps.shopify.com/metastock

Our app allows you to display inventory by location. It also allows customers to select a store that smooths out the whole shopping experience, don't the website. It is very similar to how Target and other big box retailers handle this issue, so it's a great app for brick-and-mortar stores on Shopify. Because it provides the best user experience for customers using your website. 

 

If you have any issues with the implementation just drop us a line. We're always willing to help our customers as best we can. 😀

 

Also, here is a video that describes the app and provides an overview. You may find this helpful in deciding if the app is right for you and best solves the issue. 

 

 

Hope this helps and wishing you all the best!