Articles on: Discounts

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


Overview


When managing multiple upsell offers across your cart, checkout, and post-purchase pages, it's essential to apply discounts selectively to specific offers. By utilizing the unique Offer ID assigned to each upsell in UpsellPlus, you can target individual offers with precise discounts using Shopify's Script Editor.


This is how you can target a specific offer with a specific discount.


Step-by-Step Guide


  1. Log in to Shopify Admin
  • Access your Shopify Admin panel using your credentials.


  1. Open the UpsellPlus App
  • Navigate to Apps in your Shopify Admin.
  • Select UpsellPlus from your installed apps.


  1. Locate the Offer ID
  • In the UpsellPlus app, go to the specific upsell offer you want to target.
  • The Offer ID is displayed at the top, just under the internal name.
  • For example: e766cbff-060d-4ed7-9797-ccb9d2bdcf1a


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



  1. Install and Open the Script Editor App
  • If not already installed, download the Script Editor app from the Shopify App Store.
  • Open the Script Editor from your list of installed apps.


  1. Create a New Script
  • Click on Create Script.
  • Choose the Line Item script type.


  1. Insert the Discount Script


You can use the 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


Parameters to Customize:


  • Offer ID: Replace e766cbff-060d-4ed7-9797-ccb9d2bdcf1a with the specific Offer ID you copied from UpsellPlus.
  • Discount Percentage: Adjust 0.80 to reflect the desired discount. For example, use 0.90 for a 10% discount or 0.75 for a 25% discount.
  • Discount Message: Change "Flash Sale" to the message you want customers to see, such as "Special Offer" or "Exclusive Deal".


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


  1. Save and Publish the Script


Key Considerations

  • Testing: Always perform thorough testing to confirm that discounts are applied correctly to the intended upsell offers.
  • Script Management: If you have multiple scripts, ensure they do not conflict with each other.


Related Articles


Updated on: 14/02/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!