wc_add_notice()
Add and store a notice.
Хуки из функции
Возвращает
null. Ничего (null).
Использование
wc_add_notice( $message, $notice_type, $data );
- $message(строка) (обязательный)
- The text to display in the notice.
- $notice_type(строка)
- The name of the notice type - either error, success or notice.
По умолчанию:'success' - $data(массив)
- Optional notice data.
По умолчанию:array()
Список изменений
| С версии 2.1 | Введена. |
Код wc_add_notice() wc add notice WC 11.0.1
function wc_add_notice( $message, $notice_type = 'success', $data = array() ) {
if ( ! did_action( 'woocommerce_init' ) ) {
wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
return;
}
// If this is called before the session is initialized, for example if a plugin includes this file incorrectly on
// the admin, skip doing anything to prevent errors.
if ( ! WC()->session ) {
wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before the WooCommerce session is initialized, or places where there is no session, e.g. WordPress admin.', 'woocommerce' ), '10.5' );
return;
}
$notices = WC()->session->get( 'wc_notices', array() );
// Backward compatibility.
if ( 'success' === $notice_type ) {
$message = apply_filters( 'woocommerce_add_message', $message );
}
$message = apply_filters( 'woocommerce_add_' . $notice_type, $message );
if ( ! empty( $message ) ) {
$notices[ $notice_type ][] = array(
'notice' => $message,
'data' => $data,
);
}
WC()->session->set( 'wc_notices', $notices );
}