When customer spends $50 -- offer specific product at $10

Shopify Partner
1783 256 695

So I'm trying to write a script that when the cart has $50, if they have this other specific product in the cart, give them that product for $10 instead of the original price. Here's the script:


cart_total_price = Input.cart.subtotal_price_was.cents

def compareSKUs(skusToCompare)
  compare_against = [
  skusToCompare.each do | sku |
    if compare_against.include?(sku)
      return true
      return false
Input.cart.line_items.each do | item |
if compareSKUs(item.variant.skus) && cart_total_price >= 5000
  item.change_line_price(Money.new(cents: 1000) * item.quantity, { message: "Discount Applied" })
Output.cart = Input.cart

This works. The problem however is that if they only add those products, they still get the discount applied to them. So the product is originally 44.99, so if they add 2 of them they reach the $50 limit, but it gives them the $10 price for both items so they will only be spending $20. I want them to reach the $50 limit, and then if they have, THEN apply discounts to those products. Anyone have an idea on how you would approach it? Thanks for your time.

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
Shopify Partner
132 1 19

Hi Ninthony,


So you want the discount to only be applied if the price will be > $49.99 after the discounts have been applied? So in this case the user would have to add 5 items to the cart to achieve the discount? Or do you just want the discount to be applied to a single item?


Also, SKU is only a singlular on a variant, so you should rewrite your SKU check.




Feeling a bit lost? Contact elliot@mandelbrotian.com for help with theme setup, alterations, custom functionality, and app development.