Home » WooCommerce: Redirect My Account Tab to URL

WooCommerce: Redirect My Account Tab to URL

by Tutor Aspire

It’s nice to know the stuff I share here is used on my own website! In this case scenario, I have a custom “My Courses” tab under the My Account navigation menu; instead of showing the My Account tab content with a link, I want to save time and immediately redirect users to https://www.businessbloomer.com/woocommerce-online-courses/ instead.

So, how do you redirect My Account tabs to custom URLs? Well, thankfully it’s just a matter of a few lines of code. Enjoy!

To save an extra user click to Business Bloomer logged in users, I use the snippet below to automatically redirect them to the “Online Courses” page when they click on the My Account “My Courses” tab.

PHP Snippet: Redirect My Account Tab to Custom URL

Please note that each My Account tab, whether it’s a default one or a custom one, takes a “woocommerce_account_TABURL_endpoint” hook automatically, where “TABURL” is the URL of the My Account page e.g. “edit-address”.

By “hooking” into our tab, we can then set up a redirect as soon as the tab loads. In the snippet below you must change 2 things:

  1. the hook namewoocommerce_account_TABURL_endpoint” right after “add_action”, e.g. “woocommerce_account_edit-address_endpoint“. Please make sure you pay attention to underscores and hyphens.
  2. the redirect URL inside wp_safe_redirect
/**
 * @snippet       Redirect My Account Tab to Custom URL - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 5.0
 * @donate $9     https://www.tutoraspire.com
 */
 
// Note 1: my account tab URL is "user-courses", see notes above the snippet if you wish to change the tab target

add_action( 'woocommerce_account_user-courses_endpoint', 'tutoraspire_my_account_tab_redirect_url' ); 

// Note 2: I want to redirect above tab to /woocommerce-online-courses
 
function tutoraspire_my_account_tab_redirect_url() { 
wp_safe_redirect( '/woocommerce-online-courses' );
exit;
}

Is There a (Reliable) Plugin For That?

If you’d love to code but don’t feel 100% confident with PHP, I decided to look for a reliable plugin that achieves the same result.

In this case, I recommend the YITH WooCommerce Customize My Account Page plugin. On top of setting up My Account tab redirects, you can also move the tab menu around, customize the color scheme, add banners, set up reCaptcha on the register and login forms, add, sort, rename, delete and group tabs, conditionally show tabs to a given user role and much more.

But in case you hate plugins and wish to code (or wish to try that), then keep reading 🙂

You may also like