wc_print_notice() – Print a single notice immediately.

Description

Print a single notice immediately.

Usage

wc_print_notice( $message, $notice_type, $data, $return );

Parameters

$message
( string ) required – The text to display in the notice.
$notice_type
( string ) optional default: success – Optional. The singular name of the notice type – either error, success or notice.
$data
( array ) optional – Optional notice data. @since 3.9.0.
$return
( bool ) optional – true to return rather than echo. @since 7.7.0.

Returns

void

Source

File name: woocommerce/includes/wc-notice-functions.php


Lines:

1 to 32 of 32
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
}
 

 View on GitHub View on Trac

Invoked by

    API Letters: ,,