wc_has_notice( string $message, string $notice_type = 'success' )

Check if a notice has already been added.


Description Description


Parameters Parameters

$message

(Required) The text to display in the notice.

$notice_type

(Optional) The name of the notice type - either error, success or notice.

Default value: 'success'


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/wc-notice-functions.php

function wc_has_notice( $message, $notice_type = 'success' ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return false;
	}

	$notices = WC()->session->get( 'wc_notices', array() );
	$notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
	return array_search( $message, wp_list_pluck( $notices, 'notice' ), true ) !== false;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.