Articles on: Checkout

How to automatically add a Free Gift triggered by a Discount Code

Overview



With UpsellPlus, you can automatically add a free gift when a customer applies a specific discount code at checkout. This encourages higher conversions and rewards shoppers for using promotions.

In addition to How to automatically add a Free Gift with Purchase to the cart, you can use UpsellPlus to give free gifts to your customers if you want them to be triggered by discount code:

Gift triggered by Discount

This is one of the features we offer that you can use to leverage UpsellPlus in your store and enhance the experience of your customers, plus, it will make your process simpler if you want to offer free gifts.

Step-by-Step Guide


UpsellPlus will need a working discount code to trigger the upsell, in this case, the Free Gift. So, let's create one code in your Shopify Admin

Go to the Discounts section of your Shopify store
Create an Amount Off code with the following conditions:

Coupon details
Note: The code above does not apply a discount. You could use an existing code that reduces the cart value, if you wish.

After the code has been created, it's time to edit your offer in UpsellPlus:

Select the product you want to give as a gift.
On the Smart Rules, select Discount Code and type in the code you created.
For this example, we used "WELCOMEGIFT"
Below the Smart Rules, tick Automatically add to cart when conditions are met

This is how it should look:
Upsell-Gift Setup
Using the Script Editor app, add a code that will discount the free gift to 100%.
Make sure you change the Discount Message and the Upsell ID, as Intro to Discounts explains

Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "f940b782-c0ba-4c46-9ca1-00301d09eb85"
line_item.change_line_price(line_item.line_price * 0.0, message: "Welcome Gift")
end
end
Output.cart = Input.cart


Key Tips
Promote the Discount Code: Let customers know they can unlock a free gift by using the code.
A/B Test Different Gifts: See which free products lead to higher conversion rates.

Related Articles
How to Automatically Add a Free Gift to the Cart
How to Show an Upsell Based on Cart Value

Updated on: 11/02/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!