Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I have a use case where I want to be able to create gift cards that customers can purchase from me. The flow goes like so:
What I want to know is how can I associate the gift card created with the purchase the customer made since the gift card doesn't exist as a product on the store until after they have checked out? Is it even possible?
Solved! Go to the solution
This is an accepted solution.
Hi Rye_dev_team,
Creating a gift card through Shopify's API and associating it with a customer's purchase is indeed possible, but it needs to be handled carefully. Here's a potential approach to handle this:
Create a placeholder product: You can create a placeholder product in your Shopify store for the gift card. This product can be selected by the customer and the desired amount entered as a custom note or a custom variant.
Customer purchases the placeholder product: The customer purchases placeholder gift card product in your store, entering the desired amount on the during checkout.
Capture the checkout information: After the customer finishes the checkout process, your backend can capture the checkout information, which includes the order details and the customer's information.
Create the gift card: Using the giftCardCreate mutation, you can create the gift card with the amount specified by the customer in their order.
Associate the gift card with the order and the customer: When creating the gift card, you can include a note or metadata that links the gift card to the order ID and the customer ID.
Send the gift card code to the customer: After the gift card is created, you can then send the gift card code the customer via email or other methods.
Would this approach work for your use case?
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
This is an accepted solution.
Hi Rye_dev_team,
Creating a gift card through Shopify's API and associating it with a customer's purchase is indeed possible, but it needs to be handled carefully. Here's a potential approach to handle this:
Create a placeholder product: You can create a placeholder product in your Shopify store for the gift card. This product can be selected by the customer and the desired amount entered as a custom note or a custom variant.
Customer purchases the placeholder product: The customer purchases placeholder gift card product in your store, entering the desired amount on the during checkout.
Capture the checkout information: After the customer finishes the checkout process, your backend can capture the checkout information, which includes the order details and the customer's information.
Create the gift card: Using the giftCardCreate mutation, you can create the gift card with the amount specified by the customer in their order.
Associate the gift card with the order and the customer: When creating the gift card, you can include a note or metadata that links the gift card to the order ID and the customer ID.
Send the gift card code to the customer: After the gift card is created, you can then send the gift card code the customer via email or other methods.
Would this approach work for your use case?
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
Thanks for this, I will give it a try and report back