1

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.

robinCTS
  • 5,746
  • 14
  • 30
  • 37
Benjamin Allison
  • 2,134
  • 3
  • 30
  • 55

1 Answers1

0

WC Notices will only show on WooCommerce template pages it won't show on your main home page unless it's a WooCommerce page. They are shown when the function wc_print_notices() is called.

Andrew Schultz
  • 4,092
  • 2
  • 21
  • 44