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
User | RANK |
---|---|
4 | |
2 | |
2 | |
2 | |
2 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023