I want to run a shopify script on the checkout like below but add a rejection message if the customer has a total order count of greater or equal to 1. Need some help here..
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 6956918014006
line_item.change_line_price(line_item.line_price - Money.new(cents: 60000), message: "You're eligible for the starter kit discount")
end
Then add this soemthing like this:
if customer.orders_count > 0
line_item.reject(message:"Sorry you're not eligible for this discount")
I did try the following but definitely have something wrong here..
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 6956918014006
line_item.change_line_price(line_item.line_price - Money.new(cents: 60000), message: "You're eligible for the starter kit discount")
end
customer = Input.cart.customer
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if customer.orders_count > 0
line_item.reject(message:"Sorry you're not eligible for this discount")
end
Output.cart = Input.cart