Last active
April 18, 2022 13:10
-
-
Save dylanjhunt/b46510b2f41f2709bc3c2dc939dcc210 to your computer and use it in GitHub Desktop.
Shopify Quantity Discount - Tiered Pricing Shopify Script
This file contains 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
DISCOUNTS_BY_QUANTITY = { | |
10_000 => 20, | |
1_000 => 15, | |
100 => 10, | |
10 => 5, | |
} | |
Input.cart.line_items.each do |line_item| | |
next if line_item.variant.product.gift_card? | |
quantity, discount = DISCOUNTS_BY_QUANTITY.find do |quantity, _| | |
line_item.quantity >= quantity | |
end | |
next unless discount | |
message = "#{discount}% off when buying at least #{quantity}." | |
line_item.change_line_price( | |
line_item.line_price * (Decimal.new(1) - discount.to_d / 100), | |
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
Hi, could you please briefly explain how this can be applied? Is it through the app cli?