Last active
June 15, 2019 00:20
-
-
Save jameslk/09e6a7385d86b1fc4fc91b158d259597 to your computer and use it in GitHub Desktop.
Shopify Scripts: Buy X, Y, and Z products together and get XX% off
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
ELIGIBLE_PRODUCT_IDS = [111111111, 22222222, 3333333333] # Specify which product IDs create a discount | |
DISCOUNT_AMOUNT = 0.2 # Set the discount amount here | |
cart_product_ids = Input.cart.line_items.map { |line_item| line_item.variant.product.id } | |
if ELIGIBLE_PRODUCT_IDS.all? { |product_id| cart_product_ids.include?(product_id) } | |
Input.cart.line_ites.each do |line_item| | |
discounted_price = line_item.line_price * (1.0 - DISCOUNT_AMOUNT) | |
line_item.change_line_price(discounted_price, message: "#{DISCOUNT_AMOUNT * 100}% off!") | |
end | |
end | |
Output.cart = Input.cart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment