Created
July 23, 2019 01:07
-
-
Save jameslk/3a4dadda73423e261169d1af5f321757 to your computer and use it in GitHub Desktop.
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
# This Shopify Script provides a discount when the eligible item is found and the cart | |
# has more than one item. | |
ELIGIBLE_PRODUCT_ID = 111111111 # Specify which product ID creates a discount | |
DISCOUNT_AMOUNT = 0.2 # Set the discount amount here | |
has_product_in_cart = Input.cart.line_items.any? do |line_item| | |
line_item.variant.product.id == ELIGIBLE_PRODUCT_ID | |
end | |
if has_product_in_cart && Input.cart.line_items.length > 1 | |
Input.cart.line_items.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