Skip to content

Instantly share code, notes, and snippets.

@EranSch
Last active August 29, 2015 13:57
Show Gist options
  • Save EranSch/9669753 to your computer and use it in GitHub Desktop.
Save EranSch/9669753 to your computer and use it in GitHub Desktop.
Disallow a PO Box in WooCommerce
<?php
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode($posted) {
global $woocommerce;
$postcode = (isset($posted['shipping_address_1'])) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$postcode = strtolower(str_replace(' ', '', $postcode));
if (strstr($postcode, 'pobox')) {
wc_add_notice( "Sorry, we don't ship to PO BOX addresses.", "error" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment