Skip to content

Instantly share code, notes, and snippets.

@emilyemoss
Created November 26, 2017 23:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilyemoss/ccac5b11e1c253e6e256eb614215efe0 to your computer and use it in GitHub Desktop.
Save emilyemoss/ccac5b11e1c253e6e256eb614215efe0 to your computer and use it in GitHub Desktop.
Shopify Script - Spend $X Get Y% Off
total = Input.cart.subtotal_price_was
# spend more than $150 earns 25% off
if total > Money.new(cents:100) * 150
discount = 0.25
message = "25% Off"
# spend between $50 and $150 earns 20% off
elsif total > Money.new(cents:100) * 50
discount = 0.20
message = "20% Off"
# spend less than $50 default 15% off
else
discount = 0.15
message = "15% Off"
end
Input.cart.line_items.each do |line_item|
line_item.change_line_price(line_item.line_price * (1-discount), message: message)
end
Output.cart = Input.cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment