Skip to content

Instantly share code, notes, and snippets.

@AmelieBassart
Forked from ChromeOrange/gist:4147753
Last active October 12, 2017 13:13
Show Gist options
  • Save AmelieBassart/631c6cf6c2556d447858 to your computer and use it in GitHub Desktop.
Save AmelieBassart/631c6cf6c2556d447858 to your computer and use it in GitHub Desktop.
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' ) ) {
WC_add_notice( "Sorry, we don't ship to PO BOX addresses." );
}
}
@SensicalCat
Copy link

Thanks @MrFent !
@Nallo - functions.php in your theme folder.
Now if we could just get it to highlight the address input field when it errors, that would make it complete. 👍

@jaxne
Copy link

jaxne commented Sep 18, 2017

Ditto on the thank you @MrFent !
I just tested the code that was on WooCommerce and it still allowed the order to go through. Changing up the notice line now to test again.

@rynaldos-zz
Copy link

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