mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
16 lines
724 B
Text
16 lines
724 B
Text
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' );
|
|
}
|
|
}
|