How to automatically add a gift card to customer's cart after form submission?

I want to have a multi-step form that once it is submitted, we automatically place a gift card in the customers’ cart. Using Klaviyo and Privy for our forms.

It would say…

“Fill out this form and we’ll automaically place a $10 giftcard in your cart” and they would input their email and hit next.

We would then ask them a two questions about their preferences related our product and then once it’s done the giftcard would be added. They would also have to make a minimum purchase.

I know how to create a multi-step form but my specific question is how to trigger the giftcard being added to the cart with the minimum purchase requirement?

Thanks!

Hello.

I do not know how your form works or if it is within Shopify itself.

But, what can work for you is to use the Shopify Ajax API, specifically the cart API. Where you only need to specify the product ID and the quantity to add.

https://shopify.dev/api/ajax/reference/cart

Additionally, it occurs to me that so that you don’t have to change the ID when you need to change the product, you make an integration with the theme editor.

Specifying the product you want to give away and from there extract the ID with liquid.

https://shopify.dev/themes/architecture/settings/input-settings#product

Greetings.

@WildCoffee

In the case of using a third-party for your forms you need to be able to check their request or code events to add the product to the cart from there.

If they are using AJAX and do not provide events to listen to for doing things you can intercept their request and start another one for adding the gift card product to the cart and apply a discount code to ensure the gift card is free.

From there you will want to check the cart’s contents before the customer is “linked” to the checkout to know whether or not to remove the gift card product from their cart. You could also link them directly to the checkout after adding the product and the discount if you wanted.

One thought from me could be that you use the built-in Shopify product form to collect the data as line item properties of the gift card product that will be added to the cart. That way you can try to ensure you only have the data if they have a gift card with their order.

Ultimately, as long as you can be made aware that the forms were submitted then you should be able to add the gift card product to the cart and apply a discount code for it.

Hope that helps!