Buy 3 and get 20% off

Highlighted
New Member
1 0 0

Hi 

I am trying to write a script to create a buy 3 units and get 20% off these three units. (The product IDs 6250082822 or 6250082566 ) The script below works to take 20% off 3 units if the line item is the same product ID and colour. But what I'd like to do is allow this discount to be applied accross the two product IDs and colour variations. 

Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  next if product.gift_card?
  next unless line_item.quantity == 3
  next unless product.id == 6250082822 or 6250082566 
  line_item.change_line_price(line_item.line_price * 0.80, message: "20% bundle discount")
end

Output.cart = Input.cart

Any help would be much appreciated. 

Thanks 

Shule Going 

0 Likes