5.26.22
No items found.

How to use Shopify Scripts to create an upsell-only discount

Offering a discount of at least 10% on an upsell item increases its take rate by 14%. But how do you apply a discount to a product only when it’s added as an upsell?

‍

There are two ways to do this:

‍

1/ The old way: duplicate the product and set a product-level discount. Now you have two versions of the same product. When you have over 30 SKU’s this becomes cumbersome.

‍

2/ The new way: create a Shopify Script that only applies a discount when the item is added as an upsell. To do so, we target a specific variable this product receives when it’s added as an upsell.

‍

Here’s a guide on setting up your Shopify Scripts to achieve this.

‍

You’ll need:

‍

Step 1: ​​Go to the official Shopify Script Editor App

(https://apps.shopify.com/script-editor)

Click ‘Create Script’ > Choose the type of script you’re adding. Here, we choose between a percentage (%) off a product or amount ($) off a product discount. Select your choice and click ‘Create Script’. Name your Script.

‍

Step 2: Add the code

Now we’ll add the following code:

If you’re not familiar with code, this does the following:

‍

IF the item added to the cart has “upsell_id” as a property

THEN apply a 10% discount and display the message ‘Upsell Discount’

‍

The “upsell_id” is added by our app, UpsellPlus, to all items that get upsold, so we can track upsell performance.

‍

Use the Shopify Script Editor to create an upsell only discount

‍

The key here is adding the 'if line_item.properties.has_key?("__upsell_id")'. This will look for any product that is added by UpsellPlus.

‍

Step 3: Choose your discount amount, percentage, or message

You can change the discount amount, percentage and message:

‍

Percentage discount: line_item.line_price * 0.90

Amount discount: Money.new(cents: 500)

Message: message: "Upsell Discount"

‍

Two examples:

A 10% discount:

‍

A $5 discount:

‍

‍

Note that you need to use a specific notation to get to $5 (500 cents, more on that here: https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#money)

‍

Result in checkout for both examples:

‍

‍

$5 discount
10% discount

‍

‍

Step 4: Save and publish your script and test it on your live store

If you already have existing campaigns running with Shopify Scripts, you can add this script just below it.

‍

More on discounts and some template scripts here: https://help.upsellplus.com/en/category/discounts-4otj6t/

‍

‍

‍

Jaap Vergote

Jaap Vergote

Need help implementing this?

Book a call

Ready to make every order worth more?

Launch your first offer with a 14-day free trial, or talk with our team about a Shopify Plus strategy.