wc_notice_count

Get the count of notices added, either for all notices (default) or for one.

Description

(int) wc_notice_count( (string) $notice_type = '' ); 

particular notice type specified by $notice_type.

Returns (int)

Parameters (1)

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

Usage

  1. if ( !function_exists( 'wc_notice_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-notice-functions.php'; 
  3.  
  4. // The 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_notice_count($notice_type); 
  9.  

Defined (1)

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

/includes/wc-notice-functions.php  
  1. function wc_notice_count( $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. $notice_count = 0; 
  7. $all_notices = WC()->session->get( 'wc_notices', array() ); 
  8.  
  9. if ( isset( $all_notices[ $notice_type ] ) ) { 
  10.  
  11. $notice_count = absint( sizeof( $all_notices[ $notice_type ] ) ); 
  12.  
  13. } elseif ( empty( $notice_type ) ) { 
  14.  
  15. foreach ( $all_notices as $notices ) { 
  16. $notice_count += absint( sizeof( $all_notices ) ); 
  17.  
  18. return $notice_count;