MyListing Club

Bypass WooCommerce Logout Confirmation

Building better MyListing websites. One code snippet at a time.

Overview

The Bypass WooCommerce Logout Confirmation code snippet allows for greater flexibility within a MyListing website.

Without this snippet, users will be prompted to confirm if they would like to log out, which may not be what some would consider a fluid user experience.

Implementation

  1. Grab the code snippet.
  2. Follow the provided instructions.
  3. Save your changes.
				
					//// INSTRUCTIONS: 
//// Copy and paste the code snippet below into the child theme's functions.php file.
//// You can edit the functions.php file from your WordPress dashboard (Appearance > Theme Editor) or via FTP.

--------------------------- CODE SNIPPET IS BELOW THIS LINE --------------------------- 

// BYPASS WOOCOMMERCE LOGOUT CONFIRMATION
function wc_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', 'wc_bypass_logout_confirmation' );