New customer discount problem

Shopify Partner
2 0 0

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!

0 Likes
Highlighted
Shopify Partner
2 0 0

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

0 Likes