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

Highlighted
Globetrotter
634 60 127

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 = [
                     "BGE-SET8T",
                     "BGL-SET8T",
                     "BGP-SET8T",
                     "BGW-SET8T",
                     "BLH-SET8T",
                     "BLK-SET8T",
                     "BLP-SET8T",
                     "BLT-SET8T"
                     ]
  skusToCompare.each do | sku |
    if compare_against.include?(sku)
      return true
    else
      return false
    end
  end
end
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" })
end
end
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 you'd like to make any edits to your store, please send me a direct message and we can discuss what you'd like to accomplish :D
0 Likes
Shopify Partner
134 1 15

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.

 

Cheers,

Elliott

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