Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anonymous/25affb23a39a845a21ed7a9c2fe26f0d to your computer and use it in GitHub Desktop.
Save anonymous/25affb23a39a845a21ed7a9c2fe26f0d to your computer and use it in GitHub Desktop.
OnlyGrowth.com
MINIMUM_ORDER_AMOUNT = 50 #dollars required in cart to get discount
MESSAGE = "Minimum Order $50 Promotion" #promotional message
if !Input.cart.shipping_address.province.include?("Hawaii") && !Input.cart.shipping_address.province.include?("Alaska")
if Input.cart.subtotal_price_was > (Money.new(cents:100) * MINIMUM_ORDER_AMOUNT)
Input.shipping_rates.each do |shipping_rate|
if shipping_rate.name.include?("2 Day Ground")
shipping_rate.change_name("Free 2 Day Ground", { message: "" })
shipping_rate.apply_discount(shipping_rate.price, message: MESSAGE)
end
end
end
end
Output.shipping_rates = Input.shipping_rates
@fabiensebban
Copy link

I have the following errors when I copy-paste this script in the Shopify Script Editor:

Your Cart | Error on line 4: undefined method 'include?' for nil
Empty Cart | Error: discount code requirements not met
No Customer | Error on line 4: undefined method 'include?' for nil

How can I improve this script to have no errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment