New Shopify Certification now available: Liquid Storefronts for Theme Developers

Can't update customer metafield

Solved
Jude_Huang
Shopify Partner
8 0 0

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
Shopify Staff
246 57 62

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 2 (2)
lizk
Shopify Staff
Shopify Staff
246 57 62

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
27 3 3

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