Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

StoreAPI: Clear all wc notice types in the cart validation context #5983

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/StoreApi/Utilities/NoticeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NoticeHandler {
*/
public static function convert_notices_to_exceptions( $error_code = 'unknown_server_error' ) {
if ( 0 === wc_notice_count( 'error' ) ) {
wc_clear_notices();
return;
}

Expand All @@ -42,10 +43,10 @@ public static function convert_notices_to_exceptions( $error_code = 'unknown_ser
/**
* Collects queued error notices into a \WP_Error.
*
* For example, Payment methods may add error notices during validate_fields call to prevent checkout.
* For example, cart validation processes may add error notices to prevent checkout.
* Since we're not rendering notices at all, we need to catch them and group them in a single WP_Error instance.
*
* This method will discards notices once complete.
* This method will discard notices once complete.
*
* @param string $error_code Error code for the thrown exceptions.
*
Expand All @@ -55,6 +56,7 @@ public static function convert_notices_to_wp_errors( $error_code = 'unknown_serv
$errors = new WP_Error();

if ( 0 === wc_notice_count( 'error' ) ) {
wc_clear_notices();
return $errors;
}

Expand Down