Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanjhunt/64a1c2e132db490229b5505e82fc6396 to your computer and use it in GitHub Desktop.
Save dylanjhunt/64a1c2e132db490229b5505e82fc6396 to your computer and use it in GitHub Desktop.
Since we cannot determine how much the customer has every spent, we are able to determine the total number of orders they have placed
customer = Input.cart.customer
discount = 0
message = ""
if customer
if customer.orders_count > 2 #number of orders needed to get discount
discount = 0.2 #percent discount in decimal form
message = "VIP Customer"
end
end
puts discount
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 * (1-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