Automattic\WooCommerce\StoreApi\Utilities
NoticeHandler::convert_notices_to_wp_errors
Collects queued error notices into a \WP_Error.
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 discard notices once complete.
Method of the class: NoticeHandler{}
No Hooks.
Returns
\WP_Error. The WP_Error object containing all error notices.
Usage
$result = NoticeHandler::convert_notices_to_wp_errors( $error_code );
- $error_code(string)
- Error code for the thrown exceptions.
Default:'unknown_server_error'
NoticeHandler::convert_notices_to_wp_errors() NoticeHandler::convert notices to wp errors code WC 10.8.1
public static function convert_notices_to_wp_errors( $error_code = 'unknown_server_error' ) {
$errors = new WP_Error();
if ( 0 === wc_notice_count( 'error' ) ) {
return $errors;
}
$error_notices = wc_get_notices( 'error' );
foreach ( $error_notices as $error_notice ) {
$errors->add( $error_code, wp_strip_all_tags( $error_notice['notice'] ) );
}
return $errors;
}