Skip to content

Instantly share code, notes, and snippets.

@dylanjhunt
Last active November 20, 2018 19:11
Show Gist options
  • Save dylanjhunt/a0e4352d9f69174b46ef2962574cd7f6 to your computer and use it in GitHub Desktop.
Save dylanjhunt/a0e4352d9f69174b46ef2962574cd7f6 to your computer and use it in GitHub Desktop.
min_discount_order_amount = Money.new(cents:100) * 30 #minimum amount needed to have in cart to get discount
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
500 #discount amount you are offering in cents
else
0
end
message = "Here's $5 off" #discount message shown to customer
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
@seberle12
Copy link

Hi,

I am trying to use this script but it's discounting each product by $5 instead of just the whole order. Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment