How do I only discount a product when it's added as an upsell with Script Editor?
Overview
To ensure that a discount is applied exclusively when a product is added through an upsell offer, you can implement a Shopify Script that targets items with specific upsell identifiers. This method ensures that the discount is not applied if the product is added to the cart through other means.
When you want a discount to apply to a product only when it's added as an upsell, you can use a simple Shopify Script.
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 scripts 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"].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
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 - Money.derived_from_presentment(customer_cents: 500), message: "Flash Sale"))
end
end
Output.cart = Input.cart
Parameters to Customize:
- Discount Percentage: Adjust
0.80
to reflect the desired discount. For example, use0.90
for a 10% discount. - Discount Amount: Adjust
500
to reflect the desired discount. For example, use250
for a $5 discount. - Discount Message: Change
Flash Sale
to the message you want customers to see, such asSpecial Offer
orExclusive Deal
. - Offer ID: Replace
e766cbff-060d-4ed7-9797-ccb9d2bdcf1a
with the specific offer ID from your UpsellPlus offer.
- **Save and Publish **your script.
Key Tips
- Testing: Always perform thorough testing to confirm that the discount applies only when the product is added via the upsell offer.
- Script Management: If you have multiple scripts, ensure they do not conflict with each other.
Related Articles
- Intro to Discounts
- How to Target Specific Offers with a Discount Using the Offer ID with Script Editor
Updated on: 14/02/2025
Thank you!