wc_has_notice()WC 2.1

Check if a notice has already been added.

Хуков нет.

Возвращает

true|false.

Использование

wc_has_notice( $message, $notice_type );
$message(строка) (обязательный)
The text to display in the notice.
$notice_type(строка)
The name of the notice type - either error, success or notice.
По умолчанию: 'success'

Список изменений

С версии 2.1 Введена.

Код wc_has_notice() WC 8.7.0

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;
}