Enhance the Checkout Process for PO Box Addresses!
We often get to be a natural solution for all these cases.
A PO Box or Post Office Box is a lockable box located in a post office which custo a PO Box.
This might pose a problem when you run an online sto the overall shipping workflow.
For example, John is using both FedEx and USPS for his shipping needs. However, he faces a problem where his custore.
So, among the varied list of shipping carriers, USPS is the only one permitted to its fullest potential).
Since John is facing this problem continuously, he actively seeks out for a solution. He checks whether WooCommerce forums have any tweaks for this. But he couldn’t find a solution to allow PO Boxes with WooCommerce.
Out of frustration, John decides to limit the services of other carriers and only show USPS rates in checkout (when PO Box is entered in ‘address line 1’ instead of a street address).
XAdapter helped John by developing a code snippet for this:
Go to enable this functionality.
The above snippet shows only the USPS rates when a customer enters the string “pobox” in the checkout page as shown below :
John’ cart for a physical address: Note both FedEx and USPS services are displayed.
John’ cart for a PO Box address: Only USPS service is displayed.
So now, you can easily streamline your shipping based on PO Boxes and forget all about customers choosing incorrect shipping service for PO box addresses. Now make your checkout process as smooth as ever!
Are you getting a http 500 issue as well. could you raise a support ticket so that I can have a look.
Not that I know of. All I know is that when I add the code in this post to the function file it only works for “pobox” and not any other combination. When it works, fedex is removed as a shipping option, but if I enter “p o box” or “p.o. box” it doesn’t remove fedex as a shipping option.
If I change line 9 to the suggestion below from Kevin, I get this error:
Your PHP code changes were rolled back due to an error on line 804 of file wp-content/themes/mediclinic/functions.php. Please fix and try saving again.
syntax error, unexpected ‘strstr’ (T_STRING)
This was a question, not a request.
Also this code does not work and returns SERVER ERROR 500:
Hello, we are using both the UPS and USPS Woocommerce plugins.
We want to show only USPS prices for PO Boxes.
When we try to use the example code on this page:
PHP Fatal error: Can’t use method return value in write context in /var/www/vhosts/elrhq.com/dev.elrhq.com/wp-content/themes/xstore-child/functions.php on line 22
For others having this PHP error, upgrading to PHP 5.6 fixed it for me.
Please adapt this code to include ALL variations! NOBODY actually types in “pobox”! They type in “po box” or “p.o. box” or “P.O. Box” or “PO Box” or “P.o. box” or “po. box” or “Po Box.”.
Will it work to just change line 9 to:
if ( strstr( $address, ‘pobox’ ) || strstr( $postcode, ‘pobox’ )
strstr( $address, ‘po box’ ) || strstr( $postcode, ‘po box’ )
strstr( $address, ‘p.o. box’ ) || strstr( $postcode, ‘p.o. box’ )
strstr( $address, ‘P.O. Box’ ) || strstr( $postcode, ‘P.O. Box’ )
strstr( $address, ‘PO Box’ ) || strstr( $postcode, ‘PO Box’ )
strstr( $address, ‘P.o. box’ ) || strstr( $postcode, ‘P.o. box’ )
strstr( $address, ‘po. box’ ) || strstr( $postcode, ‘po. box’ )
strstr( $address, ‘Po Box.’ ) || strstr( $postcode, ‘Po Box.’ )
Surely there is a more effecient way to check for this?
Thanks a lot for the suggestion.
We shall definitely consider it for future enhancement. But currently, we won’t be able to provide any timeline for this.
Did you get this to work? I’m having the same issue.