Created
January 30, 2024 07:35
-
-
Save darryn/e29459777202bcb7a7f537a130a4c6ae to your computer and use it in GitHub Desktop.
Shopify Script to discount items in cart based on customer tag, absence of discount code, and excluded products
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
products_to_exclude = [444750805, 444750821] #product ids to exclude | |
trigger_customer_tag = 'member-50' #customer tags to trigger script discount | |
if Input.cart&.customer&.tags.include?(trigger_customer_tag) && Input.cart&.discount_code == nil #does the customer have the right tag, and are there no discounts applied? | |
Input.cart.line_items.each do |line_item| | |
product = line_item.variant.product | |
next if product.gift_card? # don't discount gift cards | |
next if products_to_exclude.include?(product.id) # don't discount excluded products | |
line_item.change_line_price(line_item.line_price * 0.50, message: "Pro Deal - 50% Discount") #discount everything else by X% | |
end | |
end | |
Output.cart = Input.cart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment