Can we apply 75% discount on 'compare at price' using Script Editor?

@lindabr

The first thing to note is that if the discounted price is not less than the current line price the discount should not apply.

You should be able to grab the compare at price of the variant and apply the 75% discount to that. From there you would verify if that resulting price is less than the current line price of the line item and that if it is apply the discount.

It would be something like this:

Input.cart.line_items.each do |line_item|
  compare_at_price = line_item.variant.compare_at_price
  new_line_price = compare_at_price - (compare_at_price * (Decimal.new(0.75) / 100.0))

  if new_line_price < line_item.line_price
    line_item.change_line_price(new_line_price, message: '75% off original price')
  end
end

Output.cart = Input.cart

You may want to add additional conditions to target specific products or variants but without testing I believe something like that should work for you.

Hope that helps!

1 Like