How can update Customer Metafield when checkout successfully

nhtbao101
Tourist
14 0 1

This is the first time I am working with Shopify, please help me with this case.
I am using points in the customer metafield to discount for an order when the customer checkout. But I don't know how to update customer metafield on checkout page
I want to know how can I update the customer metafield after I checkout an order or submited an order successfully?
If possible, how can we do that? Thank you so much

Replies 7 (7)

Liam
Shopify Staff
2731 302 779

Hi Nhtbao101,

 

Just to understand your use-case fully - do you want to update the customer metafield during the checkout process, or after - ie: once the order is processed? When do you want the discount to be applied? 

 

Once I have a little bit more info I can recommend the best approach! 

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

nhtbao101
Tourist
14 0 1

Thank you for your reply.
About the discount, I applied it in Step-1 (checkout information) and after the order is processed, I will update the customer metafield at the moment. In addition, I want to update real-time, it's means, I will update customer Metafield immediately when the order is processed successfully. Because when the app have delay when updating discount point for the customer, they can trick to steal money of the store (order in 2 devices at the same time)

Liam
Shopify Staff
2731 302 779

There is a function for useApplyMetafieldsChange() that you can use to mutate the metafields property of the checkout - would this work in your usecase? You can see an example of how it's implemented in this tutorial.

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

nhtbao101
Tourist
14 0 1

Thanks again for your reply.

I read the docs about useApplyMetafieldsChange(). And I see this line 
"This metafield value is later associated with the order". In 
In this link 
Does this mean this function just works with the order and cart only or I am wrong? Can you confirm about it?

 
 
nhtbao101
Tourist
14 0 1

@Liam 
I just want to update customer metafield in checkout UI extension  🙁

Cpuga
Shopify Partner
41 0 5

Im trying the same any way to do it?

nhtbao101
Tourist
14 0 1

@Cpuga 
No, You cannot update customer metafield on the checkout page.
I use another method by saving the order information to DB when checkout and updating it to the customer metafield in the next date by automatic API