First off thumbs up for using script editor, such a great app from Shopify. Here is a great example to do just what you’re asking a tier discount based on total amount in the order:
Obviously you’ll have to edit the code and make some adjustments but it’s 90% there.
Once you install Script Editor, open the app and create a new line_item script and press the “Code” button. You can copy and paste the example script in there.
P.S. dollar values are literally in cents. So $50 would be 5000. I just had a test and boy it works great.
Yep I missed the filtering collections part, sorry about that. What I’m getting from documentation is that product collection is not currently available in Script API. So as an alternative a “product tag” could be used. Here is a working example just add “discount_eligible” as a tag to those products.
# Define spending thresholds, from lowest spend to highest cart value.
SPENDING_THRESHOLDS = [
{
spend: 250 * 100, # spend amount (in cents)
discount: 10 # percentage discount
},
{
spend: 500 * 100,
discount: 15
},
{
spend: 750 * 100,
discount: 20
},
{
spend: 1000 * 100,
discount: 25
}
]
# Find any applicable spending threshold.
eligible_threshold = nil
SPENDING_THRESHOLDS.each do |threshold|
if Input.cart.subtotal_price_was.cents >= threshold[:spend]
eligible_threshold = threshold
end
end
# Apply threshold.
if !eligible_threshold.nil?
Input.cart.line_items.each do |line_item|
line_item.variant.product.tags.each do |tag|
if tag == "discount_eligible"
line_item.change_line_price(line_item.line_price * (1.0 - (eligible_threshold[:discount] / 100.0)), message: "#{eligible_threshold[:discount]}% off for purchases over $#{eligible_threshold[:spend] / 100}!")
end
end
end
end
Output.cart = Input.cart
It would be nice to get the collection name and hopefully we see that soon in Scripts API, but some pros for the product tag would be not having to go back into the code to add a new collection when we can just update the product and it will be apart of the tiered discounts.
Can someone help me understand if I can use script editor for this same tiered discount (ie: Spend $100, get 15%, Spend $200, get 30%) but with a promo code attached?
Yes you can use script editor to effect the order like discount or line items. But look at Shopify’s automatic discounts I think you’ll like how easy it is to setup.