Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Able to setup the cartMetafieldsSet using StoreFrontAPI properly.
Now, my main concerns is how it will save automatically when order will placed. Or do I need to save those values using webhooks when order is placed?
I just want to setup few custom metafields on cart and than access them in Order Admin API later. But I am stuck how I can access these values.
We are not using shopify plus plan, so modifying the checkout attribute is not possible.
Using this code to create metafields for cart
const cartid = 'gid://shopify/Cart/' + carttoken;
const getcartQuery =
` mutation cartMetafieldsSet($cartID: ID!) {
cartMetafieldsSet(
metafields:[
{
ownerId: $cartID,
key: "public.materials",
type: "multi_line_text_field",
value: "95% Cotton"
},
{
ownerId: $cartID,
key: "public.manufactured",
type: "single_line_text_field",
value: "Made in Canada"
}
]) {
metafields {
namespace
key
value
type
}
userErrors {
code
field
message
}
}
}`
;
const response = await graphql(
getcartQuery, { variables: { cartID: cartid } }
);
Thank You
Hi Itooze,
Are you looking to save the metafield values on the order itself, or save them to your database when the order is made?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi Liam
I want to save these cart metafields to order itself. That is the approach I am looking for.
Thank You
HI Liam
Do you get a chance to look into this and let me know the best possible way to achieve the same.
Thank You
Hi Itooze,
I'm still looking to figure this out - do you want the metafield values to be saved to an order as an order metafield? Is there already an order metafield definition set up that should accept the cart metafield value?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @Liam Also curious what the preferred approach is on this. Looking for a way to pass information derived from cart interaction and checkout interaction to the order after checkout.