Articles on: Discounts

How to apply different discounts to different products in a multiproduct upsell

This is now a lot simpler with Functions discounts. Scripts will be sunset on August 28, 2025. To learn how to do add a functions discount: https://help.upsellplus.com/en/article/discounts-shopify-functions-and-shopify-scripts-yj7gwb/


When you create an upsell in checkout with multiple products, you might want to add different discounts to each product.

To do so, we'll use the product ID to and offer ID to target the upsell product and offer.

Th script below should be able to achieve that.

Go to your Shopify Script editor and create a new script for a % or amount off
Copy over the script below for a % of amount off
Add in your product ID's, offer ID and discount amount.
Publish!

Percentage discount:

Input.cart.line_items.each do |line_item|
Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "ADD YOUR OFFER ID HERE"
product = line_item.variant.product
next if product.gift_card?
if product.id == ADD THE PRODUCT ID OF PRODUCT 1 HERE
line_item.change_line_price(line_item.line_price * 0.40, message: "Upsell Discount")
end
if product.id == ADD THE PRODUCT ID OF PRODUCT 2 HERE
line_item.change_line_price(line_item.line_price * 0.50, message: "Upsell Discount")
end
end
end
Output.cart = Input.cart


Currency amount discount:

Input.cart.line_items.each do |line_item|
Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "ADD YOUR OFFER ID HERE"
product = line_item.variant.product
next if product.gift_card?
if product.id == ADD THE PRODUCT ID OF PRODUCT 1 HERE
line_item.change_line_price(line_item.line_price - Money.derived_from_presentment(customer_cents: 500), message: "Flash Sale")
end
if product.id == ADD THE PRODUCT ID OF PRODUCT 2 HERE
line_item.change_line_price(line_item.line_price - Money.derived_from_presentment(customer_cents: 500), message: "Flash Sale")
end
end
end
Output.cart = Input.cart


You can control these variables:
Product ID= enter the product ID of the products you want to discount. You can find this ID by going to the product in your Shopify admin and copying the ID from the url.
Discount % or amount = update the 0.90 or 500 number to reflect the discount you want for each product.
'0.90' is a 10% discount. '0.80' is a 20% discount.
'500' is 500 cents in the currency of your store, so if it's dollars, this will be $5.00
Offer ID = enter the offer ID of the multiproduct upsell

How to target specific offers with a discount using the offer ID

Updated on: 02/04/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!