Personalized checkout and custom promotions with Shopify Scripts
Hi,
I managed to get a script to work to hide Expedited Shipping for PO Boxes and show Standard Shipping instead (It's the only time we show Standard Shipping).
We launched a week ago and since then, I got 8 production errors (with dozens of sales). It's always the same RuntimeError: undefined method 'upcase' for nil
Can anyone help me figure out what's going on? I really appreciate it!
Here's the script, the error happens on row 2 where I put the word in bold:
#Script begin
#Exclude Expedited option when PO Box is present
shippingaddress1 = Input.cart.shipping_address.address1.upcase.split[0...-1].join ' '
checkpobox = ['PO BOX','POBOX','P.O BOX','PO. BOX','P.O.BOX','P.O. BOX','P.0. BOX','P.OBOX']
puts shippingaddress1
#define hideship based on checkpobox. If so, hide shipping options, otherwise allow all
if checkpobox.include?(shippingaddress1)
hideship = ['Expedited']
else
hideship = ['Standard']
end
#With hideship defined, now we loop through shipping rates to delete those that match
Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
hideship.any? { |hideship| shipping_rate.name.include?(hideship) }
end
#Script end
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024