How to add a discount to an automated upsell using Script Editor
Overview
Automated upsell offers can be enhanced by applying specific discounts, encouraging customers to add recommended products to their cart. By utilizing Shopify's Script Editor, you can implement discounts for AI-generated upsell products.
In the ShopBrain upsell offer, add a compare at price to the recommended products.
To add a discount to an AI generated upsell, we will add a script to the Script Editor.
Step-by-Step Guide
- Log in to Shopify Admin
- Access your Shopify Admin panel using your credentials.
- 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.
- Create a New Script
- Click on Create Script.
- Choose the Line Item script type.
- Insert the Discount Script
- Copy and paste the following script into the editor:
Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"]
line_item.change_line_price(line_item.line_price * 0.90, message: "Special discount")
end
end
Output.cart = Input.cart
Parameters to Customize:
- Discount Percentage: Adjust
0.90
to reflect the desired discount. For example, use0.80
for a 20% discount. - Discount Message: Change
"Special discount"
to the message you want customers to see, such as"Exclusive Offer"
or"Limited Time Discount"
.
- Save and Publish the Script
- Click Save to apply the script.
Key Tips
- 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
Thank you!