Good day,
I have tried the following approaches to block spammers from creating further accounts but unfortunately nether of the 2 approaches worked.
Users are still able to create accounts as per normal so I believe either you have custom actions or shortcodes that I am missing.
Can you please assist me, the code I tried is below.
add_action('woocommerce_register_post','is_valid_registration_email_domain', 10, 3 );
function is_valid_registration_email_domain( $username, $email, $validation_errors ){
$valid_email_domains = array( 'gmail.com', 'yahoo.com' ); // Allowed domains
$valid = false; // sets default validation to false
foreach( $valid_email_domains as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain != strtolower($d) ){
$valid = true;
break;
}
}
// Return error message for invalid domains
if( ! $valid ){
$error_text = __( "<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.", "woocommerce" );
$validation_errors->add( 'domain_whitelist_error', $error_text );
}
}
or
// Allow Registration Only from @warrenchandler.com email addresses
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domains = array("warrenchandler.com","warrenchandler.co.uk");// allowed domains
$valid = false; // sets default validation to false
foreach( $valid_email_domains as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain != strtolower($d) ){
$valid = true;
break;
}
}
// Return error message for invalid domains
if( $valid === false ){
$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );