How to limit an upsell discount to just 1 item with Script Editor
Overview
Offering exclusive discounts on upsell products can effectively encourage additional purchases. However, to prevent customers from applying the discount to multiple quantities of the same item, you can implement a Shopify Script that restricts the discount to only one unit per upsell product.
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.
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 Limitation 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")
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 (see Step 5 for customizing this). Below is the explanation of the code.
Condition Check:
- The script checks if the line item has the
__upsell_id
property, indicating it's an upsell product.
Quantity Handling:
- If the quantity is greater than one, the script splits the line item, isolating one unit to apply the discount.
- If the quantity is one, the script directly applies the discount.
- **Customize the Script **
- Discount Rate: Adjust
0.90
to change it from a 10% rate to reflect your desired discount. For example, use0.80
for a 20% discount. - Discount Message: Change
"Upsell Discount"
to a message that aligns with your branding, such as"Exclusive Offer"
or"Special Deal"
.
- Save and Publish the Script
- Click Save to apply the script.
Key Considerations
- Testing: Always perform thorough testing to confirm that the discount applies exclusively to one unit of the upsell product, even if multiple quantities are added to the cart.
- Script Management: If you have multiple scripts, ensure they do not conflict with each other.
- *
Related Articles
Updated on: 14/02/2025
Thank you!