How to get customer’s active location ID on storefront for inventory filtering?

Hi,

I’m building a third-party AI assistant for a Shopify store to improve product discovery. While suggesting products/variants, I want to filter them based on inventory at the customer’s active location (the one Shopify uses for fulfillment).

Right now, I can fetch inventory across all locations, for example:

inventoryItem {
  id
  inventoryLevels(first: 250) {
    edges {
      node {
        location {
          id
          name
        }
        quantities(names: ["available"]) {
          name
          quantity
        }
      }
    }
  }
}

This gives me inventory for each location.

The issue: I cannot find a way to determine which location the customer is actually shopping from on the storefront. Without that, I don’t know which location.id to use when filtering availability.

Question:

  • Is there a way to fetch the customer’s active/assigned location ID from the storefront (via Storefront API, checkout, or cart context)?
  • Or any workaround Shopify provides for mapping the browsing customer to the right location?

Any help would be greatly appreciated!
Thanks!

Hi @Bik_AI

There is no official or supported way to get the customer’s “active” fulfillment location via the Storefront API, cart, or checkout context. Some stores use the customer’s IP address, shipping address, or an explicit location picker to approximate the most likely fulfillment location, but this is not guaranteed to match Shopify’s actual fulfillment logic.

If you have access to the Admin API, you can fetch all locations and their inventory, and use your own logic to estimate which location would fulfill an order based on the customer’s shipping address and the merchant’s location priorities. However, this is only an estimate.