Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Can't update customer metafield

Solved

Can't update customer metafield

Jude_Huang
Shopify Partner
8 0 2

In my Checkout UI extension, I can update order metafields without any problem. But I can't update customer metafield.

 

For example, 

 

 

 

useApplyMetafieldsChange
({
  type: "updateMetafield",
  namespace: "order_details",
  key: "delivery_date",
  valueType: "string",
  value,
});​

 

 

Here order_details is a namespace under order.metafields. However the similar code,

 

 

useApplyMetafieldsChange
({
  type: "updateMetafield",
  namespace: "custom",
  key: "cust_test",
  valueType: "integer",
  value,
});

 

 

doesn't work (here custom is a namespace under customer.metafields). 

 

For order metafields, they work fine even without matching [[extensions.metafields]] in the shopify.extension.toml file. I added 

 

 

[[extensions.metafields]]
namespace = "custom"
key = "cust_test"

 

 

 in shopify.extension.toml, but I still can't read or write this meta data. The app can access protected customer data, e.g. shipping zip code. 

 

Am I still missing something, or if there is some kind of access permission I have to setup?

 

Thanks for your help.

 

--Jude

Accepted Solution (1)

lizk
Shopify Staff
246 58 78

This is an accepted solution.

Hi there 👋

 

The useApplyMetafieldsChange hook only updates metafields on the Checkout object. Once the checkout is completed the metafields are present on the resulting order. At this time during the checkout process order metafields are the only metafield that you can modify directly. 

Instead of adding a metafield to the customer during the checkout process, this could be something that is done after the order is created. You could respond to webhooks for orders that have been created, and then add the webhook to the customer. 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 4 (4)

lizk
Shopify Staff
246 58 78

This is an accepted solution.

Hi there 👋

 

The useApplyMetafieldsChange hook only updates metafields on the Checkout object. Once the checkout is completed the metafields are present on the resulting order. At this time during the checkout process order metafields are the only metafield that you can modify directly. 

Instead of adding a metafield to the customer during the checkout process, this could be something that is done after the order is created. You could respond to webhooks for orders that have been created, and then add the webhook to the customer. 

To learn more visit the Shopify Help Center or the Community Blog.

Turbofan1178
Shopify Partner
57 4 12

Apologies for reopening this. But I was wondering if you could elaborate on this with code or a link to documentation that does this:

Instead of adding a metafield to the customer during the checkout process, this could be something that is done after the order is created. You could respond to webhooks for orders that have been created, and then add the webhook to the customer. 


 Thanks

Founder, WC: Invite To WhatsApp Channel
- Invite customers to join your WhatsApp channel with a single click
- Boost outreach message open rates
- Grow sales with direct outreach on WhatsApp channels
Tanip
Shopify Partner
7 0 2

Is it accurate to say that there is currently no capability to update customer metafields through a Checkout extension in Shopify?

daniyal741
Shopify Partner
4 1 0

@lizk , Do we have any updates on this? When can we expect it to be available for all metafield resources on the checkout?