· 6 years ago · Nov 26, 2019, 10:52 AM
1//Validate email address field
2function xoo_cu_el_validate_registration_fields( $validation_error, $username, $password, $email ){
3
4 $valid_email_domains = array("gmail.com","yahoo.com");// whitelist email domain lists
5 $valid = false;
6
7 foreach( $valid_email_domains as $d ){
8 $d_length = strlen( $d );
9 $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
10 if( $current_email_domain == strtolower($d) ){
11 $valid = true;
12 break;
13 }
14 }
15 // if invalid, return error message
16 if( $valid === false ){
17 $validation_error->add( 'domain_whitelist_error', __( 'You can only register using @gmail.com or @yahoo.com emails', 'easy-login-woocommerce' ) );
18 }
19
20 return $validation_error;
21}
22add_filter( 'xoo_el_process_registration_errors', 'xoo_cu_el_validate_registration_fields', 10, 4 );