Articles on: Checkout

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

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 like this:

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.

These are the steps:

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,, and 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 the "Automatically add to cart when conditions are met"
This is how it should look like:
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 the Intro to Discounts explain
Input.cart.line_items.each do |line_item|
if"__upsell_id") and["__upsell_id"].include? "f940b782-c0ba-4c46-9ca1-00301d09eb85"
line_item.change_line_price(line_item.line_price * 0.0, message: "Welcome Gift")
Output.cart = Input.cart

Updated on: 23/02/2024

Was this article helpful?

Share your feedback


Thank you!