skip to Main Content

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


  1. 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);

    Login or Signup to reply.
  2. You have to active cookie/session for the customer by following code before calling wc_add_notice function:

    if (!WC()->session->has_session()) {
        WC()->session->set_customer_session_cookie(true);
    }
    

    It’s necessary for actions such as payment response to your website.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search