Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cameroncowden/3d0d638987a4084333a02481dff274e5 to your computer and use it in GitHub Desktop.
Save cameroncowden/3d0d638987a4084333a02481dff274e5 to your computer and use it in GitHub Desktop.
Shopify Scripts.. Script.. to remove the FedEx option if the customer enters a PO box.
found1 = false
found2 = false
is_po_box = false
if(Input.cart.shipping_address.address1)
this_address = Input.cart.shipping_address.address1
found1 = true
end
if(Input.cart.shipping_address.address1)
this_second_address = Input.cart.shipping_address.address2
found2 = true
end
#reTest = /^(((p[\s\.]?[o\s][\.]?)\s?)|(post\s?office\s?))((box|bin|b\.?)?\s?(num|number|#)?\s?\d+)/
#sadly no regex
if(found1)
if this_address.downcase.include?('p.o. box')
is_po_box = true
end
if this_address.downcase.include?('po box')
is_po_box = true
end
if this_address.downcase.include?('p.o.')
is_po_box = true
end
if this_address.downcase.include?('p.o box')
is_po_box = true
end
if this_address.downcase.include?('p.o. box')
is_po_box = true
end
if this_address.downcase.include?('po box')
is_po_box = true
end
if this_address.downcase.include?('p o box')
is_po_box = true
end
if this_address.downcase.include?('post office box')
is_po_box = true
end
if this_address.downcase.include?('p.o.b.')
is_po_box = true
end
end
if(found2)
if this_second_address.downcase.include?('p.o. box')
is_po_box = true
end
if this_second_address.downcase.include?('po box')
is_po_box = true
end
if this_second_address.downcase.include?('p.o.')
is_po_box = true
end
if this_second_address.downcase.include?('p.o box')
is_po_box = true
end
if this_second_address.downcase.include?('p.o. box')
is_po_box = true
end
if this_second_address.downcase.include?('po box')
is_po_box = true
end
if this_second_address.downcase.include?('p o box')
is_po_box = true
end
if this_second_address.downcase.include?('post office box')
is_po_box = true
end
if this_second_address.downcase.include?('p.o.b.')
is_po_box = true
end
end
if(is_po_box)
Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
shipping_rate.name.start_with?("FedEx")
end
else
Output.shipping_rates = Input.shipping_rates
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment