Personalized checkout and custom promotions with Shopify Scripts
Is there a way in Script Editor to discount a line item's compare at price instead of it's line price? We want to offer customers 75% off the original compare at price, but cannot figure out how to do it. We have only been able to offer an additional X amount off the current selling price and want to try something different.
@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!
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025