I try to add a wc notice in an admin page.
function some_hook_function() {
wc_add_notice(__('Done!'), 'notice');
wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=shop_order' ) );
exit;
}
add_action( 'some_action' , 'some_hook_function', 10);
However it doesn’t work. I am able to add an admin notice but I don’t want to do that. I just need a classical wc notice after a redirection.
2
Answers
You can’t display it on admin pages without calling
wc_print_notices()
.By default this function will echo all the notice. If however you want to get the notices, pass
true
in the function as$notices = wc_print_notices(true);
You have to active cookie/session for the customer by following code before calling wc_add_notice function:
It’s necessary for actions such as payment response to your website.