I'm processing some requests in my Wordpress theme's functions.php
, and need to set notices there.
But none of the WooCommerce methods are available. How can I access wc_add_notice()
from there?
Code from my functions.php
file:
function my_function() {
// some code
wc_add_notice('Yay!', 'success');
wp_redirect( '/' );
die();
}
add_action( 'admin_post_nopriv_action', 'my_function' );
add_action( 'admin_post_action', 'my_function' );
NOTE: There is a similar question Display Woocommerce notices on a page, but this question is not a duplicate of that one. The notices will be displayed on standard WooCommerce template files. I'm attempting to set notices from within the functions.php
file.