wc_notice_count()
Get the count of notices added, either for all notices (default) or for one. particular notice type specified by $notice_type.
No Hooks.
Returns
Int.
Usage
wc_notice_count( $notice_type );
- $notice_type(string)
- The name of the notice type - either error, success or notice.
Default:''
Changelog
| Since 2.1 | Introduced. |
wc_notice_count() wc notice count code WC 10.5.0
function wc_notice_count( $notice_type = '' ) {
if ( ! did_action( 'woocommerce_init' ) ) {
wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
return;
}
$notice_count = 0;
$all_notices = WC()->session->get( 'wc_notices', array() );
if ( isset( $all_notices[ $notice_type ] ) && is_array( $all_notices[ $notice_type ] ) ) {
$notice_count = count( $all_notices[ $notice_type ] );
} elseif ( empty( $notice_type ) ) {
foreach ( $all_notices as $notices ) {
if ( is_countable( $notices ) ) {
$notice_count += count( $notices );
}
}
}
return $notice_count;
}