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
We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024