NoticeHandler::convert_notices_to_wp_errors()public staticWC 1.0

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.

Метод класса: NoticeHandler{}

Хуков нет.


\WP_Error. The WP_Error object containing all error notices.


$result = NoticeHandler::convert_notices_to_wp_errors( $error_code );
Error code for the thrown exceptions.
По умолчанию: 'unknown_server_error'

Код NoticeHandler::convert_notices_to_wp_errors() WC 7.5.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' );

	// Prevent notices from being output later on.

	foreach ( $error_notices as $error_notice ) {
		$errors->add( $error_code, wp_strip_all_tags( $error_notice['notice'] ) );

	return $errors;