wc_print_notice()WC 2.1

Print a single notice immediately.

Return

null. Nothing (null).

Usage

wc_print_notice( $message, $notice_type, $data, $return );
$message(string) (required)
The text to display in the notice.
$notice_type(string)
The singular name of the notice type - either error, success or notice.
Default: 'success'
$data(array)
Optional notice data. @since 3.9.0.
Default: array()
$return(true|false)
true to return rather than echo. @since 7.7.0.
Default: false

Changelog

Since 2.1 Introduced.

wc_print_notice() code WC 8.6.1

function wc_print_notice( $message, $notice_type = 'success', $data = array(), $return = false ) {
	if ( 'success' === $notice_type ) {
		$message = apply_filters( 'woocommerce_add_message', $message );
	}

	$message = apply_filters( 'woocommerce_add_' . $notice_type, $message );

	// Buffer output.
	ob_start();

	wc_get_template(
		"notices/{$notice_type}.php",
		array(
			'messages' => array( $message ), // @deprecated 3.9.0
			'notices'  => array(
				array(
					'notice' => $message,
					'data'   => $data,
				),
			),
		)
	);

	$notice = wc_kses_notice( ob_get_clean() );

	if ( $return ) {
		return $notice;
	}

	echo $notice; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}