Allow display multiple error messages through registration validation

This commit is contained in:
Claudio Sanches 2019-06-19 18:09:28 -03:00
parent 9e641e08dd
commit 6989532274
1 changed files with 12 additions and 4 deletions

View File

@ -1097,9 +1097,15 @@ class WC_Form_Handler {
try {
$validation_error = new WP_Error();
$validation_error = apply_filters( 'woocommerce_process_registration_errors', $validation_error, $username, $password, $email );
$validation_errors = $validation_error->get_error_messages();
if ( $validation_error->get_error_code() ) {
if ( 1 === count( $validation_errors ) ) {
throw new Exception( $validation_error->get_error_message() );
} elseif ( $validation_errors ) {
foreach ( $validation_errors as $message ) {
wc_add_notice( '<strong>' . __( 'Error:', 'woocommerce' ) . '</strong> ' . $message, 'error' );
}
throw new Exception();
}
$new_customer = wc_create_new_customer( sanitize_email( $email ), wc_clean( $username ), $password );
@ -1130,10 +1136,12 @@ class WC_Form_Handler {
exit;
}
} catch ( Exception $e ) {
if ( $e->getMessage() ) {
wc_add_notice( '<strong>' . __( 'Error:', 'woocommerce' ) . '</strong> ' . $e->getMessage(), 'error' );
}
}
}
}
}
WC_Form_Handler::init();