Forked from dylanjhunt/Shopify Script - X% off if customer placed more than Y orders
Created
April 11, 2017 16:45
-
-
Save CodeBrotha/c96c78a166a5190418eb9b16d6bcf73d 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
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
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