Today we take a look at the WooCommerce Checkout page and our goal is to disallow placing an order to customers that enter a PO BOX address. I don’t remember where I got this snippet from, but either way I’m glad to share it again!
PHP Snippet: Disallow Shipping to PO BOX @ WooCommerce Checkout
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
22 thoughts on “WooCommerce: Disallow Shipping to PO BOX Address”
It didnt work on the Post Code/ZIP fields. the order went thru even with PO BOX
You’re right, try this revised version
Works for me! Thank you so much
Hi Rodolfo – this code is exactly what I have been searching for. Thank you.
Just a question – how could I check for either “P O Box” or “Private Bag” in each of the 2 address lines – we have 2 kinds of boxes in this country and I cannot courier to either. Just wondered how to check for multiple strings on the same line.
Hi Cat, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Works great any idea about preventing shipping to units ( appartments )
Does this cover entering in PO BOX in the postal code,
Doesn’t work for Amazon Payments.
Hey Leon, thanks for your comment! Not sure how Amazon Payments work, sorry. Do they take you to Amazon servers?
thanks for the code (again!). I found a similar one on the official WooCommerce website, but it didn’t really work for PayPal payments. But yours did! Thanks!
Ah, awesome Miroslav, thanks for your nice comment!
that was my EXACT experience…. Thank you Rodolfo!!!!
I’m new to wordpress and found your post through a Google search. Where exactly are you pasting the snipet? Is there a specific file?
Hey Nicholas, yes you can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!
I have copied and pasted your code exactly and it doesn’t seem to be working for me – any insight would be appreciated. It just continues on to the payment stage.
Hey Emma, thanks so much for your comment! This should work with the default 1-page checkout – are you using a multi-step checkout plugin instead?
This is fabulous, and super helpful!
Cheers Sarah 🙂