How to get the selected Location from a B2B customer using Checkout UI Extension

Hi,

We are creating a Checkout UI extension for our own store, where we need to show a drop-down list for the Buyer to select the Sales Rep for this order. Available Sales Reps are a list on the Company Location’s Metafields.

How can we get the selected Location and the Location’s Metafileds for a B2B customer from the UI Extension.

useCustomer is returning undefined, buyerIdentity from useExtensionAPI() only gets the customer email and we cant find a way to get B2B variables.

We get more details from a non-B2B customer, which makes no sense, the UI extension and checkout functions are supposed to be the way to customize the checkout for B2B customers. For D2C customer we already do it using liquid and JS files.

Appreciate any help.

Hi Jbriceno, You’re correct that the useCustomer hook and buyerIdentity do not provide direct access to B2B-related variables in Shopify. In order to access B2B-related variables, such as the selected location, within a Checkout UI extension, you’ll need to use a different approach. One possible solution is to leverage the Shopify Storefront API to retrieve the necessary information.

Here’s a general outline of the steps you can follow:

  1. Create a custom API endpoint or GraphQL resolver on your Shopify app’s backend to fetch the B2B-related information for a specific customer.
  2. From your Checkout UI extension, make an API request or GraphQL query to the custom endpoint or resolver, passing the customer’s identifier (e.g., customer ID or email) as a parameter.
  3. Implement the logic on your backend to retrieve the selected location and its metafields for the given customer. You can use the Shopify Storefront API or GraphQL to fetch this information. Ensure that the necessary permissions are set up for your app to access the required data.
  4. Return the retrieved data from the custom endpoint or resolver as a response to the frontend.
  5. Handle the response in your Checkout UI extension and utilize the received data to populate the dropdown list for selecting the sales rep.

This will allow you to fetch B2B-related variables and make them available in your Checkout UI extension.

Hope this helps!

buyerIdentity {
  purchasingCompany {
    company
  }
}

Why wouldn’t this query work?

Hi Martin,

This works from a Checkout Function but not from a UI Extension. Not a clue why would Shopify restrict the data on the UI Extension…