Created
November 26, 2012 11:28
-
-
Save ChromeOrange/4147753 to your computer and use it in GitHub Desktop.
Don't Ship to PO Boxes
This file contains hidden or 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
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." ); | |
} | |
} |
Not working for me either!
Andrew, I've forked and updated the gist here: https://gist.github.com/keninbassart/631c6cf6c2556d447858
Needs to be updated:
$woocommerce->add_error needs to be changed to wc_add_notice syntax. Corrected in the gist above my comment:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.