wc_has_notice function
This commit is contained in:
parent
858416605d
commit
85b4ca8c03
|
@ -89,8 +89,8 @@ class WC_Query {
|
|||
* Get any errors from querystring
|
||||
*/
|
||||
public function get_errors() {
|
||||
if ( isset( $_GET['wc_error'] ) )
|
||||
wc_add_notice( esc_attr( $_GET['wc_error'] ), 'error' );
|
||||
if ( ! empty( $_GET['wc_error'] ) && ( $error = sanitize_text_field( urldecode( $_GET['wc_error'] ) ) ) && ! wc_has_notice( $error, 'error' ) )
|
||||
wc_add_notice( $error, 'error' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
* @return int
|
||||
*/
|
||||
function wc_notice_count( $notice_type = '' ) {
|
||||
|
||||
$notice_count = 0;
|
||||
$all_notices = WC()->session->get( 'wc_notices', array() );
|
||||
|
||||
|
@ -39,6 +38,19 @@ function wc_notice_count( $notice_type = '' ) {
|
|||
return $notice_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if a notice has already been added
|
||||
*
|
||||
* @param string $message The text to display in the notice.
|
||||
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
|
||||
* @return bool
|
||||
*/
|
||||
function wc_has_notice( $message, $notice_type = 'success' ) {
|
||||
$notices = WC()->session->get( 'wc_notices', array() );
|
||||
$notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
|
||||
return array_search( $message, $notices ) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add and store a notice
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue