Disable PO Box Shipping for specific shipping methods
-
I need a way to disable PO box shipping if the chosen ship method isn’t USPS. I’ve found the code below, which disables shipping to PO Boxes, but I want to be able to ship to PO Boxes via USPS. Any suggestions would be most appreciated.
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( sprintf( __( “Sorry, we cannot ship to PO BOX addresses.”) ) ,’error’ );
}
}
- The topic ‘Disable PO Box Shipping for specific shipping methods’ is closed to new replies.