Re: How can I retrieve product variant metafields on checkout UI extension?

How can I retrieve product variant metafields on checkout UI extension?

Shopify Partner
41 2 22
Hi everyone!
Is it possible to retrieve product variant metafields on the checkout UI extension?
Neither useAppMetafields nor useMetafields react hooks don't work.
The solution I found:
  • Get variant IDs with StandardAPI.
  • Then use storefront API for each variant to retrieve metafields.

But if there are 10 line items, this requires 10 storefront API calls.

Is there any better way?

Looking for a Shopify App developer? Please visit:
Replies 3 (3)

Shopify Partner
25 1 5

Any update on this? I got the same question

Shopify Partner
6 0 2

I also came here to find the answer! Any updates Shopify?


EDIT: I found a suggestion in github:


In addition to using the storefront API, you can use the "app metafields" API. With this API, you list the metafields you want as a metafields key in your shopify.extension.toml, and those metafields are queried on a number of objects in checkout, including the products and variants in cart lines. The useAppMetafields() hook lets you look these metafields up based on the results you get from the cart lines:

import {useCartLines, useAppMetafields} from '@shopify/checkout-ui-extensions-react';

function MyExtension() {
  const firstLine = useCartLines()[0];
  const variantMetafields = useAppMetafields({id:});
  const productMetafields = useAppMetafields({id:});
Freelance Shopify Developer & Ecommerce Operator

Shopify Partner
3 0 0

Having same problem to get product metafields in webPixel extension

probably related to