WooCommerce Code Reference

NoticeHandler
in package

NoticeHandler class.

Helper class to handle notices.

Table of Contents

convert_notices_to_exceptions()  : mixed
Convert queued error notices into an exception.
convert_notices_to_wp_errors()  : WP_Error
Collects queued error notices into a \WP_Error.

Methods

convert_notices_to_exceptions()

Convert queued error notices into an exception.

public static convert_notices_to_exceptions([string $error_code = 'unknown_server_error' ]) : mixed

For example, Payment methods may add error notices during validate_fields call to prevent checkout. Since we're not rendering notices at all, we need to convert them to exceptions.

This method will find the first error message and thrown an exception instead. Discards notices once complete.

Parameters
$error_code : string = 'unknown_server_error'

Error code for the thrown exceptions.

Tags
throws
RouteException

If an error notice is detected, Exception is thrown.

Return values
mixed

convert_notices_to_wp_errors()

Collects queued error notices into a \WP_Error.

public static convert_notices_to_wp_errors([string $error_code = 'unknown_server_error' ]) : 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.

Parameters
$error_code : string = 'unknown_server_error'

Error code for the thrown exceptions.

Return values
WP_ErrorThe WP_Error object containing all error notices.