Tips

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.

Share

27 Comments

  1. abhi says:

    but where we need to add this code?

  2. 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?

    Thanks!

  3. 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 http://www.rustictaghouse.co.uk

  4. robert_viruss says:

    nice one 😉

  5. 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.

    • 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 🙁

      • 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’ ) )));

        • Magic Filou says:

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

          • 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. Magic Filou says:

    Hi! Anybody have another solution for me to reach my goal ? 🙂

  7. 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. Ozgur says:

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

    wp_destroy_current_session();
    wp_clear_auth_cookie();

  9. Isabel says:

    This works perfectly fine.

  10. Olga says:

    Works great! Thanks

  11. You made my day! thanks a lot

  12. Bhargava Prabu Reddy says:

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

  13. Tang says:

    It works for me. Great. Thanks a lot.

  14. Riz says:

    Thanks helped a lot!!

  15. Danielle says:

    Hi,

    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.

    Danielle

  16. Aung phyo Aung phyo says:

    Aung phyo

  17. John says:

    Danielle,
    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. tabraiz says:

    It worked for me, It was easy solution

  19. Clappert says:

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

    wp-login.php?action=logout&redirect_to=https%3A%2F%mysite.com%2Fshop%2Fmy-account%2F&_wpnonce=f5gty78

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

  20. 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)

    Cheers

  21. Amar Verma says:

    I tried all solution mentioned above for my blog https://amarverm.com

    but none of the solution worked out for me. 🙁

    please share tips to resolved this issues.

  22. Lagbena tor valobasa says:

    My FB regular suing halp my login fb account

Leave a Reply

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