Personalized checkout and custom promotions with Shopify Scripts
Hello, I am running into an issue. On our store we want to have products of certain types discounted based on the quantity of said types.
I almost have it working correctly, though whenever there's more of 1 matching type I can't seem to apply the correct discount we're wanting.
PRODUCT_TYPES = ["Pony O","PonyOSingle"] cart = Input.cart cart.line_items.each do |line_item| product = line_item.variant.product # Check the product type if PRODUCT_TYPES.collect{|el| el.downcase }.include?(product.product_type.downcase) # Check product quantity if line_item.quantity == 1 # Apply discount line_discount = line_item.change_line_price(Money.new(cents: 799) * line_item.quantity, message: "") end
if line_item.quantity == 2
# Apply discount
line_discount = line_item.change_line_price(Money.new(cents: 999) * line_item.quantity, message: "") end
end end Output.cart = Input.cart
What the code seems to be doing is counting how many "Pony O" ,"PonyOSingle" there are collectively and applying the discount to only 1 of the items. I need to apply the discount to each of the items matching with the correct value
The price of 1 item should come out to 7.99, the price of the 2nd item is only 2.00 more, then every item after that is supposed to increase by an additional 5.00 until 100 quantity (then we wanna post a message to tell the customer to contact us for bulk pricing)
So the way it should work, is adding 1 "Pony O" or "PonyOSingle", then the 2nd "Pony O" and/or "PonyOSingle" would be 2.00, or 9.99 if it's two "Pony O" or two "PonyOSingle".
We have several types of items we want to apply tier discounts to, with several types of the items sharing the same "quanity" number.
Sorry this seemed confusing to explain what's going on, and what the desired effect is, I can try to give anymore information needed. I appreciate anyone that can help me figure this out. Thank you. ( if it's needed, this is the page that we want this script to work for. https://www.ponyo.com/pages/mix-match-save )
Hey there Mate. Not a Shopify Scripts Expert by far. But thought I might give some input if that is alright with you.
This is unsupported by Shopify, And I would not recommend using it to make your script and using it has not been updated since October 2019. But it might be worth trying to replicate it and see how it handles it and see if you can see any difference.
https://jgodson.github.io/shopify-script-creator/
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025