Tutor LMS: Enroll in the Next Course After Completing One
Builds a learning path by enrolling students in the next Tutor LMS course automatically when they complete the previous one.
Opens WPIDE on
Code
if ( ! function_exists( 'tutor_utils' ) ) {
return;
}
// Completed course ID => next course IDs.
$wpide_tutor_next_courses = array(
101 => array( 102 ),
);
add_action( 'tutor_course_complete_after', function ( $course_id, $user_id = 0 ) use ( $wpide_tutor_next_courses ) {
$user_id = $user_id ? (int) $user_id : get_current_user_id();
foreach ( $wpide_tutor_next_courses[ (int) $course_id ] ?? array() as $next ) {
if ( $user_id && get_post_type( $next ) === tutor()->course_post_type && ! tutor_utils()->is_enrolled( $next, $user_id ) ) {
tutor_utils()->do_enroll( (int) $next, 0, $user_id );
}
}
}, 10, 2 );
Notes
Best used with free follow-up courses.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.