Block Checkout for Listed Emails and Phone Numbers
Stops orders from customers on your block list, such as repeat chargeback offenders, matched by email address, email domain or phone number.
Opens WPIDE on
Code
$wpide_block_list = array(
'emails' => array( '[email protected]' ), // Full email addresses.
'domains' => array( 'bad-domain.example' ), // Email domains.
'phones' => array( '+44 7700 900123' ), // Phone numbers.
);
add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) use ( $wpide_block_list ) {
$email = strtolower( trim( (string) ( $data['billing_email'] ?? '' ) ) );
$domain = false !== strpos( $email, '@' ) ? substr( strrchr( $email, '@' ), 1 ) : '';
$phone = preg_replace( '/\D/', '', (string) ( $data['billing_phone'] ?? '' ) );
$phones = array_map( function ( $number ) {
return preg_replace( '/\D/', '', $number );
}, $wpide_block_list['phones'] );
$blocked = in_array( $email, array_map( 'strtolower', $wpide_block_list['emails'] ), true )
|| ( $domain && in_array( $domain, array_map( 'strtolower', $wpide_block_list['domains'] ), true ) )
|| ( strlen( $phone ) > 5 && in_array( $phone, $phones, true ) );
if ( $blocked ) {
$errors->add( 'validation', 'Sorry, we are unable to process this order. Please contact us for help.' );
}
}, 10, 2 );
Notes
Phone numbers are compared by digits only, and the message is deliberately neutral so blocked customers are not told why.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.