How to Enable WooCommerce Redirect My Account Tab to URL function?

At times, you wish to redirect users to a custom URL directly. This simple coding facilitates ease to your website users. So, let’s learn about how to enable WooCommerce redirect My Account Tab to URL. 

In the following example, you can see a My Account navigation menu. Further, it contains a custom ‘My Courses’ tab under the My Account. So, if a visitor wishes to open online courses, then he has to get through My Account & My courses tab. As you can see it’s a bit of a lengthy process. Instead, you can put an ‘Online courses’ link at the place of ‘My Account’. This is how users will redirect to online courses with a single click.

WooCommerce-Redirect-My-Account-Tab-to-URL

PHP Snippet: WooCommerce Redirect My Account Tab to URL

Every My Account tab takes the ‘woocommerce_account_TABURL_endpoint’ hook automatically. It doesn’t matter whether My Account tab is default or custom. Herein, ‘TABURL’ is the URL of your My Account tab. Eg, ‘edit-address’

After that, you can initiate redirect as soon as the tab loads by “hooking” into tab. 

In the below snippet, you must change two things.

  1. the hook name – Also, change “woocommerce_account_TABURL_endpoint” present right after “add_action”. For example, “woocommerce_account_edit-address_endpoint”. Make sure that you place hyphens & underscores accurately while doing so. 
  2.  the redirect URL present inside wp_safe_redirect
// 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', 'phpsof_my_account_tab_redirect_url' ); 
 
// Note 2: I want to redirect above tab to /woocommerce-online-courses
  
function phpsof_my_account_tab_redirect_url() { 
   wp_safe_redirect( '/woocommerce-online-courses' );
   exit;
}

Is there any other way to redirect My Account Tab to URL?

Yes, if you find coding a little bit hard, then you can install a plugin. One can use YITH WooCommerce Customize My Account Page plugin. Using it, you can set the My Account tab redirects. Also, it is possible to move tabs around, change color schemes, add banners, etc.

Moreover, you can also establish reCaptcha on login & register forms. One can even add, delete, rename, sort, & group tabs. Also, these tabs can be made visible conditionally to particular user groups. There is much more you can discover! 

Where do you add this snippet?

So, this is how you can enable WooCommerce redirect My Account Tab to URL. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file.

Is this snippet still valid?

So, this way, you can learn about WooCommerce redirect My Account Tab to URLI have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected. Share it further if you find this snippet useful for you and it had saved your time.

Also Read, How to Add WordPress Customizer Setting in WooCommerce?

How to Add Custom Field to Product Variations?

Important links: WooCommerce – https://woocommerce.com/