Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets My Account Redirect

WooCommerce: Custom Logout Redirect @ My Account

Last Revised: Apr 2023

STAY UPDATED

Whenever a customer logs out from WooCommerce, they are redirected to the My Account page URL.

But when you use separate Login and Registration pages, or whenever you have custom landing pages you wish your customers to see instead of the default My Account page, we can set a custom URL by code and safely redirect the just-logged-out customer there. Here’s the quick fix – enjoy!

Tired of redirecting logged out customers to the My Account page? Here’s a quick PHP snippet so that you can define a custom redirect URL

PHP Snippet: Redirect Logged Out Customers to Custom URL @ My Account

/**
 * @snippet       Custom Redirect for Logouts @ WooCommerce My Account
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_logout_default_redirect_url', 'bbloomer_redirect_after_woocommerce_logout' );

function bbloomer_redirect_after_woocommerce_logout() {
   return 'https://example.com/see-you-soon';
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Custom Add to Cart URLs – The Ultimate Guide
    In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by…
  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

6 thoughts on “WooCommerce: Custom Logout Redirect @ My Account”

  1. danielle
    March 21, 2024

    In my case I had to use

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

    to redirect to home on logout. Other URLs can be chosen using the permalink and wc_get_page_permalink call.

    Reply
    1. Rodolfo Melogli
      April 18, 2024

      Thank you!

      Reply
  2. Christian Probst
    August 27, 2023

    Hi there!
    Your code-snippet is very good and works right away! Thanks, I became a fan. 🙂
    Do you have a similar snippet or solution for a “redirect after password reset” ? I have a good looking and working login-form and I want to leave the WooCommerce-Login out of sight as much as possible.

    I would become a supporter right away if you have such a redirect in your large collection! I did not find it on your page, but maybe … how knows?
    I am a complete newbie to WooCommerce and feel blessed to have found your site.
    Thank you very much for your work you already did and for your answer in advance.
    (I hope this is the right place to write !?)
    Kind regards, Christian

    Reply
    1. Rodolfo Melogli
      August 28, 2023

      Hello Christian, thanks for your lovely message and for having joined the Business Bloomer Club!

      In case of a successful password reset, the “woocommerce_customer_reset_password” hook triggers, and you can use it to redirect users to wherever you like.

      Something like this should work:

      add_action( 'woocommerce_customer_reset_password', 'bbloomer_redirect_after_password_reset' );
      
      function bbloomer_redirect_after_password_reset() {
         $url = 'https://whatever.test';
         wp_safe_redirect( $url );
         exit;
      }
      

      Let me know

      Reply
  3. Whitney Mitchell
    May 18, 2023

    I am using your custom login/register/redirect snippets, however the redirect to the homepage after logout does not seem to work. it takes me back to the default woocommerce login/register screen.

    /**
     * @snippet       WooCommerce User Registration Shortcode
     */
       
    add_shortcode( 'wc_reg_form_bbloomer', 'bbloomer_separate_registration_form' );
         
    function bbloomer_separate_registration_form() {
       if ( is_user_logged_in() ) return '<p>You are already registered</p>';
       ob_start();
       do_action( 'woocommerce_before_customer_login_form' );
       $html = wc_get_template_html( 'myaccount/form-login.php' );
       $dom = new DOMDocument();
       $dom->encoding = 'utf-8';
       $dom->loadHTML( utf8_decode( $html ) );
       $xpath = new DOMXPath( $dom );
       $form = $xpath->query( '//form[contains(@class,"register")]' );
       $form = $form->item( 0 );
       echo $dom->saveXML( $form );
       return ob_get_clean();
    }
    
    /**
     * @snippet       WooCommerce User Login Shortcode
     */
      
    add_shortcode( 'wc_login_form_bbloomer', 'bbloomer_separate_login_form' );
      
    function bbloomer_separate_login_form() {
       if ( is_user_logged_in() ) return '<p>You are already logged in</p>'; 
       ob_start();
       do_action( 'woocommerce_before_customer_login_form' );
       woocommerce_login_form( array( 'redirect' => wc_get_page_permalink( 'myaccount' ) ) );
       return ob_get_clean();
    }
    
    /**
     * @snippet       Redirect Login/Registration to My Account
     */
     
    add_action( 'template_redirect', 'bbloomer_redirect_login_registration_if_logged_in' );
     
    function bbloomer_redirect_login_registration_if_logged_in() {
        if ( is_page() && is_user_logged_in() && ( has_shortcode( get_the_content(), 'wc_login_form_bbloomer' ) || has_shortcode( get_the_content(), 'wc_reg_form_bbloomer' ) ) ) {
            wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );
            exit;
        }
    }
    
    /**
     * @snippet       Custom Redirect for Logouts @ WooCommerce My Account
     */
     
    add_filter( 'woocommerce_logout_default_redirect_url', 'bbloomer_redirect_after_woocommerce_logout' );
     
    function bbloomer_redirect_after_woocommerce_logout() {
       return 'https://therowdyrose.com/';
    }
    
    Reply
    1. Rodolfo Melogli
      May 19, 2023

      So, it redirects you to the My Account page it seems… Not fully sure. This happens when you click on the “LOGOUT” tab of the My Account page? Or where are you trying to log out from?

      Reply
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

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


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Redirect Empty Paginated Category Pages (404)
  • WooCommerce: Complete Button @ Order Admin
  • WooCommerce: Allow Guest Checkout For Existing Customers
  • WooCommerce: Simplify Free Checkout
  • WooCommerce: Inject Ad After the nth Product @ Shop Page

Latest Comments

  1. Rodolfo Melogli on WooCommerce: Separate Login, Registration, My Account Pages
  2. Rodolfo Melogli on WooCommerce: Complete Button @ Order Admin
  3. Rodolfo Melogli on WooCommerce: Failed Orders Monitor & Temporary Lockdown

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x