WooCommerce – Redirect to a custom page after logging out

By default, WooCommerce will redirect customers to the My Account page after logging out. However, you may want them to go somewhere else – here’s how.

Firstly, you’ll need to make sure that you are overriding the default WooCommerce template files in your theme. If you’ve already got a woocommerce folder in your theme’s directory, you’ll be okay to continue onwards. If you don’t see one, please first take a look at the Template Structure Documentation and ensure that the correct template files are copied to your theme.

Now let’s open up the file found in /wp-content/YOUR_THEME/woocommerce/myaccount/my-account.php.

Approximately around line 21, you will find the following line:

wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) )

We’re going to want to change this line to set a custom URL to redirect to after logging out. If, for example, you wanted to send customers to Google after logging out, you could change it to this:

wp_logout_url( 'http://google.com/' )

You can even use functions like the core WordPress home_url function to redirect customers to the home page, like so:

wp_logout_url( home_url() )

If you’d like, you can read more about the wp_logout_url function in the WordPress Codex.

Views (6057)

Leave a Reply

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

eight + 10 =