Bypass “Are you sure you want to log out?” message in WooCommerce

In the latest versions of WooCommerce, when a customer clicks the โ€œlogoutโ€ button in their account, they see a message:

You may find that you want to bypass this message and just log the user out immediately. To do so, all you need is a simple code snippet. Add this using the Code Snippets plugin, or your preferred method.

This checks if the logout endpoint is set, and if it is, logs the user out straight away and redirects to the My Account page. You can add any URL in place of wc_get_page_permalink( 'myaccount' ) for a different redirect location.


James is the founder of Iconic and an experienced WooCommerce plugin developer.



  1. Avatar abhi says:

    but where we need to add this code?

  2. Avatar Corey Rubadue says:

    Hi there, it seems if I put the logout link in as a submenu I still get the dashboard pop-up. Any thoughts?


  3. Avatar Gemma Wild says:

    I’ve been tearing my hair out trying to solving this one, hehe! Thanks so much for posting, works perfectly for me over at

  4. Avatar robert_viruss says:

    nice one ๐Ÿ˜‰

  5. Avatar James Kemp says:

    Hey, you could try this:

    wp_logout_url( get_permalink( 10 ) );

    Where 10 is your primary goodbye page ID. WPML should get the ID for translated pages automatically based on the language.

    • Avatar Magic Filou says:

      Hi James
      Thanks for this tip but I tried with this code . :
      wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( get_permalink( 5261 ) )));
      And it still sending me to my goodbye page from my spanish logout link ๐Ÿ™

      • Avatar Magic Filou says:

        neither :
        wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( get_permalink( ‘5261’ ) )));
        wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( wc_get_permalink( ‘5261’ ) )));
        wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( wc_get_page_permalink( ‘5261’ ) )));

        • Avatar Magic Filou says:

          neither :
          wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( get_page_link( ‘5261’ ) )));

          • Avatar Magic Filou says:

            This one :
            wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( get_permalink( get_page_by_title( ‘mygoodbyepage’ ) ) ))); send to the good page but in main language :-/

  6. Avatar Magic Filou says:

    Hi! Anybody have another solution for me to reach my goal ? ๐Ÿ™‚

  7. Avatar Jeremy says:

    Thanks worked great!

    But what if I want to stay on the current page? For instance, client logs out on cart page and stay at the cart page. Or if client is on a specific category page, it will still be on that category page after logout?

  8. Avatar Ozgur says:

    This function wasn’t enough for me for proper logout so I added these lines below to make sure user logs out


  9. Avatar Isabel says:

    This works perfectly fine.

  10. Avatar Olga says:

    Works great! Thanks

  11. You made my day! thanks a lot

  12. Avatar Bhargava Prabu Reddy says:

    Thanks a lot!!! It solved my problem in wordpress.

  13. Avatar Tang says:

    It works for me. Great. Thanks a lot.

  14. Avatar Riz says:

    Thanks helped a lot!!

  15. Avatar Danielle says:


    I have a child theme set up, however, i am unable to find the woocommerce threads in here.

    Could you please tell me where exactly i need to add this code? Is it in the functions.php of my child theme? Also, do i need to remove anything else out of the current code?

    I look forward to your reply.


  16. Avatar Aung phyo Aung phyo says:

    Aung phyo

  17. Avatar John says:

    Go to,
    Word Press Dashboard -> Appearance -> Theme Editor.

    On the right side, at the top, you’ll see a “Select theme to edit” menu.
    Select (Your Theme) Child.

    Under the menu you’ll see “Theme Files”. It should show style.css and functions.php (those 2 files should be in your Child theme. If they’re not there just copy them from the main theme.)

    Select functions.php.

    In the main window, just paste the whole code at the bottom, then click Update File. If it updates correctly and there are no errors, it will says, “File updated successfully.”

    That’s it.

  18. Avatar tabraiz says:

    It worked for me, It was easy solution

  19. Avatar Clappert says:

    Thanks for this – however, it still uses the /wp-login.php as follows;


    How to avoid wp-login page altogether (I have it blocked in htaccess)

  20. Avatar onionwhoiam says:

    This had been driving me barmy. Code works great!

    Handy tip – I’ve noticed that if you inspect the index of the ‘logout’ link from the user dashboard you can copy the url and use it for a custom link or endpoint for additional menu logout options (y)


  21. Avatar Amar Verma says:

    I tried all solution mentioned above for my blog

    but none of the solution worked out for me. ๐Ÿ™

    please share tips to resolved this issues.

  22. Avatar Lagbena tor valobasa says:

    My FB regular suing halp my login fb account

  23. Avatar TokyoGuy says:

    Words for me using,
    Woocommerce V4.2.0
    Wordpress Version 5.4.1

    If it helps, go to:
    Appearance -> Theme Editor -> on the right side, select functions.php

    You should see your Child Theme functions.php content.
    There is a line that says,

    /* Add your own functions below this line.
    ======================================== */

    copy paste that code as it`s given here, into the space below that line.
    (and click Save ๐Ÿ™‚

  24. Avatar DHIRESH PAHUJA says:

    It worked, Thank you!

  25. Avatar James B says:


    Very helpful.

    I made one change to your scripting:

    the line:

    wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( wc_get_page_permalink( ‘myaccount’ ) ) ) );

    I changed it to redirect back to Homepage ( get_home_url() ):

    wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( get_home_url() ) ) );

  26. Avatar Dennis Prins says:

    Thanks, but the page myaccount can be cached.
    So add a refresh. See full code:

    function woocommerce_bypass_logout_confirmation() {
    global $wp;
    if ( isset( $wp->query_vars[‘customer-logout’] ) ) {
    wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( wc_get_page_permalink( ‘myaccount’ ) ) ) );
    add_action( ‘template_redirect’, ‘woocommerce_bypass_logout_confirmation’ );

Leave a Reply

Your email address will not be published. Required fields are marked *