How to Merge Learndash and Woocommerce Account Pages?

By default, your Learndash and Woocommerce have their own account pages and for the end user that can be a bit of cumbersome experience. Therefore, in this tutorial I’m going to show you how to merge Learndash and Woocommerce account pages in a way that all your important data (courses, orders, account details etc.) can be accessed from one place.

Kadence theme

SAVE 10% COUPON: SIMPLEHACKS

This is what the end result will look like.

How to Merge Learndash and Woocommerce Account Pages?

How to Merge Learndash and Woocommerce Account Pages?

Here are the steps you need to take in order to merge Learndash and Woocommerce account pages.

Step 1: Install Code Snippets plugin

Code Snippets plugin is a free plugin which allows your to run PHP/HTML/CSS/JavaScript code snippets on your site without the need to modify functions.php. The plugin can be found here. In this tutorial we are going to use this plugin to add some code snippets.

Another option, paste the code snippets shown below to your child theme’s functions.php file.

Step 2: Add “Courses” endpoint to Woocommerce

Since we need a new endpoint to be shown on the Woocommerce account page, we need to create a new endpoint. So, create a new snippet in Code Snippets and (Snippets >> Add new) paste this code to the code box. Read the explanations inside the snippets.

With the help of this snippet here below I’ll add the Courses endpoint and Courses page to the Woocommerce account page. I want to show all the user courses on the Woocommerce Courses page I‘ going to use the profile shortcode [ld_profile] inside the snippet.

class My_Custom_My_Account_Endpoint {

	/**
	 * Custom endpoint name.
	 *
	 * @var string
	 */
	public static $endpoint = 'your-courses'; // HERE GOES THE ENDPOINT URL. IF YOU ADD courses THEN THE ENDPOINT URL WILL BE /my-account/courses/

	/**
	 * Plugin actions.
	 */
	public function __construct() {
		// Actions used to insert a new endpoint in the WordPress.
		add_action( 'init', array( $this, 'add_endpoints' ) );
		add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );

		// Change the My Accout page title.
		add_filter( 'the_title', array( $this, 'endpoint_title' ) );

		// Insering your new tab/page into the My Account page.
		add_filter( 'woocommerce_account_menu_items', array( $this, 'new_menu_items' ) );
		add_action( 'woocommerce_account_' . self::$endpoint .  '_endpoint', array( $this, 'endpoint_content' ) );
	}

	/**
	 * Register new endpoint to use inside My Account page.
	 *
	 * @see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
	 */
	public function add_endpoints() {
		add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );
	}

	/**
	 * Add new query var.
	 *
	 * @param array $vars
	 * @return array
	 */
	public function add_query_vars( $vars ) {
		$vars[] = self::$endpoint;

		return $vars;
	}

	/**
	 * Set endpoint title.
	 *
	 * @param string $title
	 * @return string
	 */
	public function endpoint_title( $title ) {
		global $wp_query;

		$is_endpoint = isset( $wp_query->query_vars[ self::$endpoint ] );

		if ( $is_endpoint && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) {
			// New page title.
			$title = __( 'Your courses', 'woocommerce' );

			remove_filter( 'the_title', array( $this, 'endpoint_title' ) );
		}

		return $title;
	}

	/**
	 * Insert the new endpoint into the My Account menu.
	 *
	 * @param array $items
	 * @return array
	 */
	public function new_menu_items( $items ) {
		// Remove the logout menu item.
		$logout = $items['customer-logout'];
		unset( $items['customer-logout'] );

		// Insert your custom endpoint.
		$items[ self::$endpoint ] = __( 'Your courses', 'woocommerce' );

		// Insert back the logout item.
		$items['customer-logout'] = $logout;

		return $items;
	}

	/**
	 * Endpoint HTML content.
	 */
	public function endpoint_content() {
		echo do_shortcode('[ld_profile]'); // HERE GOES LEARNDASH SHORTCODE
	}

	/**
	 * Plugin install action.
	 * Flush rewrite rules to make our custom endpoint available.
	 */
	public static function install() {
		flush_rewrite_rules();
	}
}

new My_Custom_My_Account_Endpoint();

// Flush rewrite rules on plugin activation.
register_activation_hook( __FILE__, array( 'Your course', 'install' ) );

Step 3: Change the endpoint order (optional)

Currently the new Courses endpoint is the last one before logout but I want to change the position of this endpoint. Therefore, I‘m going to add this snippet to the Code Snippets. You and customize the order as you find suitable for your site.

function woo_my_account_order() {
	$myorder = array(
		'dashboard'          => __( 'Dashboard', 'woocommerce' ),
		'courses'    => __( 'Courses', 'woocommerce' ),
		'orders'             => __( 'Orders', 'woocommerce' ),	
		'edit-account'       => __( 'Edit account', 'woocommerce' ),
		'customer-logout'    => __( 'Log out', 'woocommerce' ),
	);
	return $myorder;
}
add_filter ( 'woocommerce_account_menu_items', 'woo_my_account_order' );

Step 4: Redirect user to the Learndash Courses tab after login

I have a modal login on my site header and if someone is logging in he/she will stay on the same page he/she was before login. I want the user to be redirected to My account >> Courses endpoint. And I don’t want this redirection to happen to the administrator or author roles.

So, I’ll add this snippet to the Code snippets. Pay attention thou

function woo_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator') or $user->has_cap( 'author')) {
$url = admin_url();
} else {
$url = home_url('/my-account/courses/'); // HERE GOES THE REDIRECTION URL
}
}
return $url;
}
add_filter('login_redirect', 'woo_login_redirect', 10, 3 );

If previous redirection is not working on your site then try to add thi piece of code here below. There are some additional options for you to redirect your user.

add_filter( 'woocommerce_login_redirect', 'learndash_login_redirect', 9999, 2 );
function learndash_login_redirect( $redirect, $user ) {
    if ( wc_user_has_role( $user, 'customer' ) ) {
       // $redirect = get_home_url(); // homepage
       // $redirect = wc_get_page_permalink( 'shop' ); // shop page
       $redirect = '/my-account/courses/'; // custom URL same site
        //$redirect = 'https://custom.url'; // custom URL other site
        //$redirect = add_query_arg( 'password-reset', 'true', wc_get_page_permalink( 'myaccount' ) ); // custom My Account tab
    }
    return $redirect;
}

Step 5: Redirect Learndash Edit profile link to Woocommere Edit account link

At this point we already have successfully merged Learndash and Woocommerce account pages but there are some other things to consider. For example, there is a Edit profile link under the Leardash profile avatar and clicking on that link opens up WordPress backend profile.

I don’t like it at all and since I want the user to stay on the My account page and edit his/her account there, I will add this snippet to the Code snippets.

add_filter( 'get_edit_user_link', function( $link, $user_id ) {
	$link = "/my-account/edit-account/"; // HERE GOES THE EDIT ACCOUNT ENDPOINT URL
	return $link;
}, 30, 2 );

Step 6: Create a new nice looking My account dashboard

I have written a full tutorial how to customize you Woocommerce account page with customizer. Or with Elementor. Take a look at this post here.

The end result will be something like that. You just need to add Courses link and customize the look to your needs.

How To Customize WooCommerce My Account Page with Gutenberg?

Step 7: Remove old Woocommerce my account dashboard navigation

So, you have created a new dashboard but the old navigation links are still there on the sidebar? Well, in order to customize your Woocommerce my account dashboard there is one more thing you need to do. And that means removing this navigation.

Therefore, go to Appearance >> Customizer >> Additional CSS and add this bit of a CSS code.

.woocommerce-MyAccount-navigation {
display:none;
}
.woocommerce-account .woocommerce-MyAccount-content {
    width: 100%;
}

This bit of a code will remove the old navigation links and set the content to be shown in 100% width.

Bonus Tips on How to Merge Learndash and Woocommerce Account Pages

Below are two additional bonus tips on how to merge Learndash and Woocommerce account pages. This will make your users end experience a bit better.

Bonus tip 1: Disable Woocommerce logout confirmation

By default, Woocommerce won’t log you right out but instead it asks the confirmation whether you really want to do it. I find this annoying and therefore I usually disable it with this small piece of code here below. Add it to the Code snippets and you’re good to go.

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

Bonus tip 2: Redirect user to the front page after logout

If you won’t use this code here below, your users will be redirected to the My account page. If you want them to be redirected to the front page instead, then add this code to the Code snippets.

add_action('wp_logout','logout_redirect');
function logout_redirect(){
    wp_redirect( home_url() );
    exit;
}

Video: How to Merge Learndash and Woocommerce Account Pages?

Useful Tips

Here are some of my favorite Wordpress tools

Thank you for reading this article. I hope you found it helpful as you build your own websites and e-commerce sites. Here are some tools I use as a Wordpress developer and enthusiast that I hope you’ll also find helpful.

These are affiliate links, so if you do decide to use any of them, I’ll earn a commission and this helps me create these tutorials and make Youtube videos. But in all honesty, these are the exact tools that I use and recommend to everyone, even my friends and family.

Themes: For the last couple of years I have two go-to themes which I use for every kind of projects. Those two themes are Blocksy theme and Kadence Theme. On this site and my Youtube channel you’ll see a lot of tutorials I have made about them. If you would like to get a 10% discount for both of them then:

Contact forms: There are hundreds of contact forms out there but Fluent Forms is the one I like the most. If you need a 20% discount then use this link (save 20% coupon is WPSH20).

Gutenberg add-ons: If I need a good Gutenberg blocks add-on then Kadence Blocks is the one I have used the most. You’ll get 10% discount with the coupon SIMPLEHACKS here.

Website migration: While building a website you probably need a good plugin that can help you with the migration, backups, restoration and staging sites. Well, WpVivid is the one I have used for the last couple of years. If you use this link along with the WPSH20 coupon you’ll get 20% discount.

Woocommerce extensions: There are a bunch of Woocommerce extensions that I really like but the one that stands really out is Advanced Dynamic Pricing. Once again, you’ll get a 20% discount if you use this link here (save 20% coupon is WPSH20)

Web Hosting: For getting started, I really like A2 Hosting. They have the dedicated and fast Wordpress hostinh and support has also been fast and responsive. If you’re more tech savvy and want to have a really fast managed cloud hosting then I recommend Cloudways. (Btw, this site is hosted in Cloudways.)

To see all my of most up-to-date recommendations, check out this resource that I made for you!

Do you want to thank me and buy me a beer?

Every donation is entirely welcome but NEVER required. Enjoy my work for free but if you would like to thank me and buy me a beer or two then you can use this form here below.

Choose amount

Best selling plugins

Default image
Janek T.
I am a Wordpress enthusiast who has been making websites since 2011. In this site I am offering simple to follow tips on how to use Wordpress and Woocommerce. If you want to be the first to be notified about the new tutorials then please subscribe to my Youtube channel here Follow me in Twitter here
Articles: 72