Personalized checkout and custom promotions with Shopify Scripts
Hey everyone! I'm new to this so please bear with me.
I currently have a cart script that is essentially running a bunch of rules based on customer tags. It's working well.
It gets started with this:
def apply(line_item)
line_item.change_line_price(line_item.line_price * @discount, message: @message)
end
What I'd like to do is wrap it in an IF statement so the rules won't apply if the line item is on sale, eg compare at price is greater than price, or even better, compare at price = nil. However I cannot get it to work!
def apply(line_item)
if line_item.compare_at_price = nil
line_item.change_line_price(line_item.line_price * @discount, message: @message)
end
end
Any clues would be very much appreciated!
For some reason, today the editor was showing me an error which helped track it down!
In the end this seemed to work:
def apply(line_item)
unless line_item.variant.compare_at_price
line_item.change_line_price(line_item.line_price * @discount, message: @message)
end
end
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024