Bypass Woocommerce Logout “Are you sure you want to log out?” message
-
Hi there,
I would like to bypass the woocommerce logout “Are you sure you want to logout?” message where the user will be redirect to Home/My Account page once they click the Logout button.
I have add these two codes to bypass Woocommerce logout message and remove the WordPress logout screen, as my client request to do so.
//woocommerce logout 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' ) ) ) ); header("Refresh:0"); exit; } } add_action( 'template_redirect', 'woocommerce_bypass_logout_confirmation' );
//wordpress logout add_action('check_admin_referer', 'logout_without_confirm', 10, 2); function logout_without_confirm($action, $result) { /** * Allow logout without confirmation */ if ($action == "log-out" && !isset($_GET['_wpnonce'])) { $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://trademark.intellect-worldwide.com/my-account/'; $location = str_replace('&', '&', wp_logout_url($redirect_to)); header("Location: $location"); die; } }
However it didn’t work smoothly. When user click Logout it will redirect to the expected page(My Account) but then when user click ‘Home’ button after they click Logout the navigation menu still showing ‘My Account’ https://ibb.co/hCDm2PJ instead of ‘Login’ https://ibb.co/J7M1dwt.
Any suggestion how can I fix this?
Thank you in advance.
The page I need help with: [log in to see the link]
- The topic ‘Bypass Woocommerce Logout “Are you sure you want to log out?” message’ is closed to new replies.