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!
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024