WC_Admin_Notices::remove_notices()public staticWC 1.0

Remove a given set of notices.

An array of notice names or a regular expression string can be passed, in the later case all the notices whose name matches the regular expression will be removed.

Method of the class: WC_Admin_Notices{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Admin_Notices::remove_notices( $names_array_or_regex, $force_save );
$names_array_or_regex(array|string) (required)
An array of notice names, or a string representing a regular expression.
$force_save(true|false)
Force saving inside this method instead of at the 'shutdown'.
Default: false

WC_Admin_Notices::remove_notices() code WC 8.9.0

public static function remove_notices( $names_array_or_regex, $force_save = false ) {
	if ( ! is_array( $names_array_or_regex ) ) {
		$names_array_or_regex = array_filter( self::get_notices(), fn( $notice_name ) => 1 === preg_match( $names_array_or_regex, $notice_name ) );
	}
	self::set_notices( array_diff( self::get_notices(), $names_array_or_regex ) );

	if ( $force_save ) {
		// Adding early save to prevent more race conditions with notices.
		self::store_notices();
	}
}