WooCommerce - My Account - logout and redirect to Homepage

10,360
add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){

  wp_redirect( home_url() );
  exit();

}
Share:
10,360
Rich72
Author by

Rich72

Updated on June 05, 2022

Comments

  • Rich72
    Rich72 almost 2 years

    Once a user is in their My Account page on WooCommerce I'd like them to hit logout and be redirected to my Homepage rather than end up on the login page.

  • Rich72
    Rich72 about 5 years
    I've added this into my function.php file. When I clicked to access My Account the login page did not fire. Nothing fired in fact. Is it not as simple as adding this code into the function.php file?
  • Rich72
    Rich72 about 5 years
    I added the code into my child theme. apexgray.co.uk/my-account
  • Rich72
    Rich72 about 5 years
    I'll add the code back into the function.php file again and let you know...
  • Rich72
    Rich72 about 5 years
    Maybe my question wasn't clear. When the user has logged into their account and they've finished, when they hit logout I ideally would like them to go to the home page.
  • Rich72
    Rich72 about 5 years
    I think my original question was confusing...!
  • Rich72
    Rich72 about 5 years
    works a charm Mujeeba! Thank you. Wish I knew how to do this!