wc_get_notices

Returns all queued notices, optionally filtered by a notice type.

Description

(array|mixed) wc_get_notices( (string) $notice_type = '' ); 

Returns (array|mixed)

Parameters (1)

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

Usage

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

Defined (1)

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

/includes/wc-notice-functions.php  
  1. function wc_get_notices( $notice_type = '' ) { 
  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. $all_notices = WC()->session->get( 'wc_notices', array() ); 
  7.  
  8. if ( empty( $notice_type ) ) { 
  9. $notices = $all_notices; 
  10. } elseif ( isset( $all_notices[ $notice_type ] ) ) { 
  11. $notices = $all_notices[ $notice_type ]; 
  12. } else { 
  13. $notices = array(); 
  14.  
  15. return $notices;