mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Retrieve validation errors from notices
This commit is contained in:
parent
d6bd403b5a
commit
838978fcf6
1 changed files with 20 additions and 2 deletions
|
@ -42,8 +42,26 @@ class CheckoutFormValidator extends WC_Checkout {
|
|||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
@$this->validate_checkout( $data, $errors );
|
||||
|
||||
if ( $errors->has_errors() ) {
|
||||
throw new ValidationException( $errors->get_error_messages() );
|
||||
// Some plugins call wc_add_notice directly.
|
||||
// We should retrieve such notices, and also clear them to avoid duplicates later.
|
||||
// TODO: Normally WC converts the messages from validate_checkout into notices,
|
||||
// maybe we should do the same for consistency, but it requires lots of changes in the way we handle/output errors.
|
||||
$messages = array_merge(
|
||||
$errors->get_error_messages(),
|
||||
array_map(
|
||||
function ( array $notice ): string {
|
||||
return $notice['notice'];
|
||||
},
|
||||
wc_get_notices( 'error' )
|
||||
)
|
||||
);
|
||||
|
||||
if ( wc_notice_count( 'error' ) > 0 ) {
|
||||
wc_clear_notices();
|
||||
}
|
||||
|
||||
if ( $messages ) {
|
||||
throw new ValidationException( $messages );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue