Once users are logged in and enrolled, course page sometimes becomes irrelevant for the users. I have seen many clients asking if they can redirect users directly to lesson/topic/focus mode upon clicking course link from their profiles, course grid and other page.

For that, a simple snippet exists, which just does that.

I would recommend using Code snippets plugin to paste this snippet. Following is the snippet you will need.

<?php

add_action('template_redirect', function () {
	if (is_user_logged_in()) {
		$q_object = get_queried_object();
		if (($q_object) && (is_a($q_object, 'WP_Post')) && ($q_object->post_type == 'sfwd-courses')) {
			if (sfwd_lms_has_access($q_object->ID)) {
				$steps = learndash_get_course_steps($q_object->ID);
				if (count($steps)) {
					wp_redirect(get_permalink($steps[0]));
					die();
				}
			}
		}
	}
}

, 1);

?>

This code send user to course based upon if he is logged in or not. I will soon be updating with a new LearnDash snippet which will check enrolment status of current course, and will redirect based upon that.

Similar Posts

Leave a Reply

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