Skip to content

Instantly share code, notes, and snippets.

@gbot
Last active November 16, 2021 10:11
Show Gist options
  • Save gbot/3ebdb6ac0330443fe758 to your computer and use it in GitHub Desktop.
Save gbot/3ebdb6ac0330443fe758 to your computer and use it in GitHub Desktop.
WP: Redirect to home page for WooCommerce login and logout. #ST3
/*----------------------------------------------------------------------------*/
// redirects for login / logout
/*----------------------------------------------------------------------------*/
add_filter('woocommerce_login_redirect', 'login_redirect');
function login_redirect($redirect_to) {
return home_url();
}
add_action('wp_logout','logout_redirect');
function logout_redirect(){
wp_redirect( home_url() );
exit;
}
@AppleTechy
Copy link

Alright so I was pointed to your php file. Can I just add this to the theme's function.php file? Rather than the WooCommerce plugin folder?

@Nikoogle
Copy link

Quick and easy.
Thank you.

@corypina
Copy link

Thank you from 2019! I was having a tough time getting the logout redirect to work on a WooCommerce site. I'm assuming WooCommerce makes the logout redirect misbehave, but whatever it is, it solved my problem.

@binits10
Copy link

binits10 commented Jun 1, 2020

Thank you it worked in 2020 :)

@diegoALCE95
Copy link

Worked in almost 2022.

But for security reasons, you must use wp_safe_redirect instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment