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
We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024