Articles on: Discounts

How to limit an upsell discount to just 1 item with Script Editor

If you want to create a strong incentive to have a customer buy another item, you can offer a nice discount on an upsell product.

If you're offering this as an exclusive discount, you might want to limit the quantity of items that can be bought at the discounted price to 1.

This is the Shopify Script you can use to achieve that:

Input.cart.line_items.each do |line_item|
	if line_item.properties.has_key?("__upsell_id")
		if line_item.quantity > 1
			discounted_items = line_item.split(take: 1)
			Input.cart.line_items << discounted_items
		else
			line_item.change_line_price(line_item.line_price * 0.90, message: "Upsell Discount")
		end
	end
end
Output.cart = Input.cart


In this example, the discount is 10% and limited to just 1 item.

Updated on: 23/07/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!