wc_add_notice
Add and store a notice.
Description
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
if ( !function_exists( 'wc_add_notice' ) ) { require_once '/includes/wc-notice-functions.php'; } // The text to display in the notice. $message = ''; // The singular name of the notice type - either error, success or notice. [optional] $notice_type = 'success'; // NOTICE! Understand what this does before running. $result = wc_add_notice($message, $notice_type);
Defined (1)
The function is defined in the following location(s).
- /includes/wc-notice-functions.php
- function wc_add_notice( $message, $notice_type = 'success' ) {
- if ( ! did_action( 'woocommerce_init' ) ) {
- wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
- return;
- }
- $notices = WC()->session->get( 'wc_notices', array() );
- // Backward compatibility
- if ( 'success' === $notice_type ) {
- $message = apply_filters( 'woocommerce_add_message', $message );
- }
- $notices[ $notice_type ][] = apply_filters( 'woocommerce_add_' . $notice_type, $message );
- WC()->session->set( 'wc_notices', $notices );
- }