Personalized checkout and custom promotions with Shopify Scripts
I'm having a problem with Shopify Script Editor and this example script ("New customer discount" - %off for new customers): https://help.shopify.com/en/manual/apps/apps-by-shopify/script-editor/examples#new-customer-discount
The script now applies the discount only if you have 2+ items in your cart, but only for the last product of the cart, not for all the line items. Shouldn't it grant the discount to the whole order, right? And also for the orders with just one item in cart. Any suggestions would be greatly appreciated!
I found a solution to this now by editing the code of the example "Percentage off next order if customer accepts marketing". It works perfectly now. Here's the code if someone needs it:
# Define the discount for eligible customers.
DISCOUNT_AMOUNT = 5
# Checks to see if this is a customer's first order
if (!Input.cart.customer.nil? && Input.cart.customer.orders_count == 0)
Input.cart.line_items.each do |line_item|
line_item.change_line_price(line_item.line_price * (1.0 - (DISCOUNT_AMOUNT / 100.0)), message: "#{DISCOUNT_AMOUNT}% discount!")
end
end
Output.cart = Input.cart
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025