A space to discuss online store customization, theme development, and Liquid templating.
Hello.
I want to add custom data to each user who buy a product.
Like if someone buy from my store, i want to add data on his account like a SQL database.
Can i do it with shopify liquid or anything else ?
Also, is there a way to have a database (not attached to customer) in a shopify website ?
Thanks!
Solved! Go to the solution
This is an accepted solution.
@fbd that is perfect! You are posting inside the Shopify APIs and SDKs, thats is not a liquid based solution, is a app based solution, you can check the guide to build it.
Lets me explain, in Shopify you cat get subscribed to some event is dispatched in the Shopify backend with Webhooks (check the order/paid event topic for your case) in that moment that receipt a notification, you can check the line_orders of the order details with data that are in the same notification, with your rules to determine if you need to update the customer data with the Admin API.
Other option that i commented, for do the same, is collect all orders data periodically (with a CRON) to check the line_items to determine if you need to update the customer data.
- How to register a webhook: https://shopify.dev/docs/api/admin-rest/2022-04/resources/webhook
- How to update a customer: https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer
- How to get orders list: https://shopify.dev/docs/api/admin-rest/2022-04/resources/order
Note: every buyer is a customer in Shopify, if purchase as guest, is a non-registered customer identified by the email at moment of the purchase, and you can add notes, tags, metafields..etc
Hi @fbd,
I like use tags for that, you can use the webhook yo subscribe to order topic and tag the user, other alternative is a CRON job that process our orders and tagging the users, in any case, you need write some code or external apps for that.
Thanks to responding me!
I forgot to say that I am a developer, but I am new in the shopify liquid ecosystem.
I am trying to know how it works and it is not a problem to add some code.
You spoke about tags, webhook and cron, but I don't understand the link with how I could add data to my user, and non-user ?
This is an accepted solution.
@fbd that is perfect! You are posting inside the Shopify APIs and SDKs, thats is not a liquid based solution, is a app based solution, you can check the guide to build it.
Lets me explain, in Shopify you cat get subscribed to some event is dispatched in the Shopify backend with Webhooks (check the order/paid event topic for your case) in that moment that receipt a notification, you can check the line_orders of the order details with data that are in the same notification, with your rules to determine if you need to update the customer data with the Admin API.
Other option that i commented, for do the same, is collect all orders data periodically (with a CRON) to check the line_items to determine if you need to update the customer data.
- How to register a webhook: https://shopify.dev/docs/api/admin-rest/2022-04/resources/webhook
- How to update a customer: https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer
- How to get orders list: https://shopify.dev/docs/api/admin-rest/2022-04/resources/order
Note: every buyer is a customer in Shopify, if purchase as guest, is a non-registered customer identified by the email at moment of the purchase, and you can add notes, tags, metafields..etc
Ok. In my store i want to do something like this: when customer buys 5 articles, he gets +50 points. If he buys 10 articles, he gets +100 points again.
And if I understand, you advise me to use Webhook for "knowing when user has bought", and then change user's custom metafield which is "points" with this https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer
Just to make sure of an expert opinion, could this system work?
And also, to use webhook, do i need to create an application ?
Yes, for webhooks you need a apikey, this only can do with an app (public or private)
Last question to really understand lol: and with the app, we can also update a customer (with the link you gave me)