Articles on: Discounts

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

If you have multiple upsells running in your cart, checkout and post-purchase pages, this is how you can target a specific offer with a specific discount.

In the UpsellPlus app, every offer has an offer ID. It is displayed at the top, just under the internal name.




You can use this offer ID to target an offer with a discount. In the Script Editor, you can add the following script to do so:

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"
line_item.change_line_price(line_item.line_price * 0.8, message: "Flash Sale")
end
end
Output.cart = Input.cart


To thread multiple offers each with a different discount, you can use a threaded script:

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"
line_item.change_line_price(line_item.line_price * 0.8, message: "Flash Sale")
end
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "ADDOFFERID"
line_item.change_line_price(line_item.line_price * 0.5, message: "Special Discount")
end
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "ADDOFFERID"
line_item.change_line_price(line_item.line_price * 0.4, message: "Promotion")
end
end
Output.cart = Input.cart

Updated on: 23/07/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!