Script editor error getting discount code

Highlighted
New Member
13 0 0

In the script editor I get three errors:

discount code requirements not met (your cart)
discount code requirements not met (empty cart)
discount code requirements not met (no customer)

The cart isn't empty and I have a customer selected. My script:

Input.shipping_rates.each do |shipping_rate|
  if (shipping_rate.source == "fedex" && shipping_rate.code == 'FEDEX_GROUND') || (shipping_rate.source == 'usps' && shipping_rate.code == 'Priority')
    if Input.cart.discount_code.code && Input.cart.discount_code.code == "FREESHIP"
      shipping_rate.apply_discount(shipping_rate.price * 1, message: "Discounted shipping")
    end
  end
end

Output.shipping_rates = Input.shipping_rates 

 

0 Likes