Last active
May 15, 2020 18:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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