Are you sure you want to log out

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

Do you think your customers get annoyed when they see this ” Are you sure you want to log out ” message after they click the log out button?

Are you sure you want to log out message on woocommerce acconnt page

Well,

At least I get annoyed by this unnecessary process which serves no real purpose (at least not for me).

Good news is you can easily disable this, I’ll show you how.

  1. Disable “Are You Sure You Want To Log Out” Message
  2. How to Add PHP Code
  3. Why You Should Disable This Feature

Disable “Are you sure you want to log out” Message.

All you have to do is add the following code snippet in your theme’s functions.php file

/* Disable "Are You Sure You Want To Log Out" Message
 * @author Garry Singh(wpglorify)
 * @link https://wpglorify.com/are-you-sure-you-want-to-log-out/?
 */

function wpglorify_bypass_logout_confirmation() {
    global $wp;
 
    if ( isset( $wp->query_vars['customer-logout'] ) ) {
        wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
        exit;
    }
}
 
add_action( 'template_redirect', 'wpglorify_bypass_logout_confirmation' );

This checks if the logout endpoint is set.

And if it is…

It will log the user out straight away and redirects to the My Account page.

In case you would like to redirect users to another page instead of ‘myaccount’, you can replace the permalink to anything else in the line number 10. wc_get_page_permalink( ‘myaccount’ ).

How to Add PHP Code

The Code Snippets plugin makes it very easy to not just add PHP snippets to your website but also manage all the snippets you add.

You can activate and deactivate certain snippets, and even adds notes about what they do. It even has better error handling to avoid the PHP error scenarios.

To install it, simply go to Plugins > Add New and search for Code Snippets.

The traditional or normal way to add PHP snippets to your theme is to add directly in your theme’s functions.php file.

However, make sure you are using a child theme otherwise you will lose all changes once you update your theme.

Why You Should Disable this feature

Short answer: For user experience

Last Year, WooCommerce update prompts a message when a customer clicks the “logout” button in their account, they see a message: Are you sure you want to log out

But

In some themes, This message is so dull that it’s almost impossible to see the message box, especially on mobile phones.

When this happens to me the very first time I thought my website is broken and there is a problem with WooCOmmerce Cache etc, etc, etc.

After few tries, I noticed this annoying message at the bottom of the my-account page in light green color.

which was almost impossible to notice. And nobody will try to read content on the account page.

But visitors will think that your website is broken and once they have this doubt they might not even return to shop again on your website and abandon your website forever without logout.

What do you think, Have any question? Don’t forget to leave a comment below.

If you liked this article, then please follow us on Facebook for WordPress tutorials. You can also find us on Twitter and Google.

Leave a Reply

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