Discount code requirements not met error

David63
New Member
13 0 0

I'm working on a script that applies free shipping on specific shipping methods if the code "FREESHIP" is used. When I try to write this script I get an error that says:

 

Discount code requirements not met (Your cart)
Discount code requirements not met (Empty cart)
Discount code requirements not met (No customer)

The code I'm using:

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 && Input.cart.discount_code == "FREESHIP"
      shipping_rate.apply_discount(shipping_rate.price * 1, message: "Discounted shipping")
    end
  end
end

Output.shipping_rates = Input.shipping_rates

 

0 Likes
KJWebPro
Shopify Expert
20 0 2

I'm getting the same error. It occurs for me whenever I enter a free shipping discount code into the Script Input, even if the code has no requirements to use and even if the script itself is basically blank:

Output.shipping_rates = Input.shipping_rates

Which leads me to believe this is a Shopify error that can't handle Free Shipping discount codes in the Script Editor input for testing, for some reason.

0 Likes
Fabien_Sebban
Shopify Partner
5 0 1

I'm getting the same issue. Did you find a way to solve it?

 

I tried the following if statement to solve the problem :

 

if Input.cart
   # apply free shipping
end

But it still does not work.

 

 

0 Likes
Bengk
Shopify Partner
14 0 6

Same. Script editor can't handle free shipping discount code it appear.

0 Likes
Click
Shopify Partner
4 0 14

Yeah, there's an issue with the live debugging in the editor.  But, you can actually get the code to work even though the editor complains.  Just FYI that I've been able to get around this by ignoring the error, saving and then testing on the site.  It would be great to get this resolved on the Shopify end though!

JØhn
Explorer
39 5 10

Just finding this now, years later - same issue, can't debug checkout codes because it gives an empty cart error even when the test cart meets the criteria or there are no criteria to meet. Pretty annoying, given debugging Shopify Scripts is already one of the hackiest things to try doing.

0 Likes
shanisingh03
New Member
2 0 2

So The problem is when you add any Coupon Code in Input CART For Testing It Will Give you This Error on Line 1, However, The Script Will Works Fine.

I think you can try removing Free Coupon Code From Input It will Work like a charm.

Cheers!!