wc_add_notice

Add and store a notice.

Description

wc_add_notice( (string) $message, (string) $notice_type = 'success' ); 

Parameters (2)

0. $message (string)
The text to display in the notice.
1. $notice_type — Optional. (string) => 'success'
The singular name of the notice type - either error, success or notice. [optional]

Usage

  1. if ( !function_exists( 'wc_add_notice' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-notice-functions.php'; 
  3.  
  4. // The text to display in the notice. 
  5. $message = ''; 
  6.  
  7. // The singular name of the notice type - either error, success or notice. [optional] 
  8. $notice_type = 'success'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_add_notice($message, $notice_type); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-notice-functions.php  
  1. function wc_add_notice( $message, $notice_type = 'success' ) { 
  2. if ( ! did_action( 'woocommerce_init' ) ) { 
  3. wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', woocommerce ), '2.3' ); 
  4. return; 
  5.  
  6. $notices = WC()->session->get( 'wc_notices', array() ); 
  7.  
  8. // Backward compatibility 
  9. if ( 'success' === $notice_type ) { 
  10. $message = apply_filters( 'woocommerce_add_message', $message ); 
  11.  
  12. $notices[ $notice_type ][] = apply_filters( 'woocommerce_add_' . $notice_type, $message ); 
  13.  
  14. WC()->session->set( 'wc_notices', $notices );