woocommerce_registration_errors │ filter-hook │ WC 7.2.0

Allows you to change the set of errors when registering a new WooCommerce user.

Fires before a WooCommerce user is created and before wp_insert_user() is called. This makes it possible to perform the required checks and return an error based on them when necessary.

Usage

add_filter( 'woocommerce_registration_errors', 'wp_kama_woocommerce_registration_errors_filter', 10, 3 );

/**
 * Function for `woocommerce_registration_errors` filter-hook.
 * 
 * @param \WP_Error $errors     Error object.
 * @param string    $username   Customer username.
 * @param string    $user_email Customer email address.
 *
 * @return \WP_Error
 */
function wp_kama_woocommerce_registration_errors_filter( $errors, $username, $user_email ){
	// filter...
	return $errors;
}
$errorsWP_Error
An instance of WP_Error.
$username
The username.
$email
The user's email.

Examples

#1 Prevent users with mail.ru email addresses from registering

add_filter( 'woocommerce_registration_errors', 'woocommerce_add_registration_errors', 10, 3 );

/**
 * Returns errors
 *
 * @param WP_Error $errors
 *
 * @return WP_Error
 */
function woocommerce_add_registration_errors( $errors, $username, $email ) {
	if ( strpos( $email, '@mail.ru' ) !== false ) {
		$errors->add( 'registration-error-invalid-email', 'Use an email address other than mail.ru.' );
	}

	return $errors;
}

Changelog

Since 7.2.0 Introduced.

Where the hook is called

wc_create_new_customer()
woocommerce_registration_errors
woocommerce/includes/wc-user-functions.php 134
$errors = apply_filters( 'woocommerce_registration_errors', $errors, $username, $email );

Where the hook is used in WooCommerce

Usage not found.