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 |
---|---|
2 | |
2 | |
2 | |
1 | |
1 |
Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023Summary of EventsBeginning in January of 2023, some merchants reported seeing a large amo...
By Trevor May 15, 2023With 2-Factor Authentication being required to use Shopify Payments, we’re here to help yo...
By Imogen Apr 26, 2023