commerce
commerce copied to clipboard
How to use shopify metafields?
Is their currently any way to use shopify metafields? Right now i have a scenario where i need to pass data from add to cart to the order metafield. Is this possible? Basically trying to attach more order information. TIA!
Yes this is possible, here's how I did it:
- Add your metafield query in
packages\shopify\src\utils\queries\get-product-query.ts
# ...
myMetafield: metafield(namespace: "my_namespace", key: "my_key") {
description
id
key
namespace
value
valueType
}
- Add property to the
Product
type inpackages\commerce\src\types\product.ts
export type Product = {
// ...
myMetafield: Metafield
}
export interface Metafield {
description: string
id: string
key: string
namespace: string
value: string // depend on your metafield content type
valueType: string
}
- I can now use it inside the
ProductSidebar
component for example
// ...
<Collapse title="Care">
{ product.myMetafield.value }
</Collapse>
Hey there! Thank you for your contribution. We have decided to take Next.js Commerce in a new direction and will be closing out current PRs and issues due to this change. Please see this PR for more details: https://github.com/vercel/commerce/pull/966