wc_add_notice()WC 2.1

Add and store a notice.

Return

null. Nothing (null).

Usage

wc_add_notice( $message, $notice_type, $data );
$message(string) (required)
The text to display in the notice.
$notice_type(string)
The name of the notice type - either error, success or notice.
Default: 'success'
$data(array)
Optional notice data.
Default: array()

Changelog

Since 2.1 Introduced.

wc_add_notice() code WC 8.6.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;
	}

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