Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created November 26, 2012 11:28
Show Gist options
  • Save ChromeOrange/4147753 to your computer and use it in GitHub Desktop.
Save ChromeOrange/4147753 to your computer and use it in GitHub Desktop.
Don't Ship to PO Boxes
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode( $posted ) {
global $woocommerce;
$address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
$replace = array(" ", ".", ",");
$address = strtolower( str_replace( $replace, '', $address ) );
$postcode = strtolower( str_replace( $replace, '', $postcode ) );
if ( strstr( $address, 'pobox' ) || strstr( $postcode, 'pobox' ) ) {
$woocommerce->add_error( "Sorry, we don't ship to PO BOX addresses." );
}
}
@simonlk
Copy link

simonlk commented Apr 24, 2015

Hey buddy is this still working fine for you? This isn't working with the latest WooCommerce. I've tested without any plugins, am yet to test with a fresh install though.

@chmchm-zz
Copy link

Not working for me either!

@AmelieBassart
Copy link

Andrew, I've forked and updated the gist here: https://gist.github.com/keninbassart/631c6cf6c2556d447858

@nickrouty
Copy link

nickrouty commented Jul 28, 2016

Needs to be updated:

$woocommerce->add_error needs to be changed to wc_add_notice syntax. Corrected in the gist above my comment:

https://gist.github.com/keninbassart/631c6cf6c2556d447858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment