wc_get_notices()
Returns all queued notices, optionally filtered by a notice type.
No Hooks.
Returns
Array[].
Usage
wc_get_notices( $notice_type );
- $notice_type(string)
- The singular name of the notice type - either error, success or notice.
Default: ''
Changelog
| Since 2.1 | Introduced. |
wc_get_notices() wc get notices code WC 10.4.3
function wc_get_notices( $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;
}
$notices = array();
if ( ! WC()->session ) {
return $notices;
}
$all_notices = WC()->session->get( 'wc_notices', array() );
if ( empty( $notice_type ) ) {
$notices = $all_notices;
} elseif ( isset( $all_notices[ $notice_type ] ) ) {
$notices = $all_notices[ $notice_type ];
}
return $notices;
}