Auto Detect PO Box Shipping Method
-
Hello – We need to return a shipping method based on if a user enters “PO Box” as a shipping address. We found a code snippet that will disable PO Box delivery. Instead of returning the error “Sorry, we don’t ship to PO BOX addresses.”, could it be customized to select a specific shipping method if the criteria is met?
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." ); } }
Thanks in advance!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Auto Detect PO Box Shipping Method’ is closed to new replies.