wc_has_notice

Check if a notice has already been added.

Description

wc_has_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_has_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_has_notice($message, $notice_type); 
  12.  

Defined (1)

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

/includes/wc-notice-functions.php  
  1. function wc_has_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 false; 
  5.  
  6. $notices = WC()->session->get( 'wc_notices', array() ); 
  7. $notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array(); 
  8. return array_search( $message, $notices ) !== false;