Created
December 17, 2018 14:59
-
-
Save dylanjhunt/d5b29786ed597754f7df107b02f9a246 to your computer and use it in GitHub Desktop.
Variable discount Shopify Script - https://dylanjh.com guides
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min_discount_order_amount = Money.new(cents:100) * 50 | |
min_discount_order_amount_2 = Money.new(cents:100) * 100 | |
total = Input.cart.subtotal_price_was | |
discount = if total > min_discount_order_amount_2 | |
1000 | |
elsif total > min_discount_order_amount | |
500 | |
else | |
0 | |
end | |
message = "My message" | |
Input.cart.line_items.each do |line_item| | |
product = line_item.variant.product | |
next if product.gift_card? | |
line_item.change_line_price(line_item.line_price - Money.new(cents: discount), message: message) unless discount == 0 | |
end | |
Output.cart = Input.cart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment