Articles on: Discounts

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

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|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a"
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 6172318073022
line_item.change_line_price(line_item.line_price * 0.90, message: "Upsell Discount")
end
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a"
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 7842318073022
line_item.change_line_price(line_item.line_price * 0.90, message: "Upsell Discount")
end
end
Output.cart = Input.cart


Currency amount discount:

Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a"
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 6172318073022
line_item.change_line_price(line_item.line_price - Money.derived_from_presentment(customer_cents: 500), message: "Flash Sale")
end
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a"
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 7842318073022
line_item.change_line_price(line_item.line_price - Money.derived_from_presentment(customer_cents: 500), message: "Flash Sale")
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

Updated on: 26/04/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!