LearnDash: Enroll in the Next Course After Completing One
Builds a learning path by enrolling students in the next course automatically as soon as they complete the previous one.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
// Completed course ID => next course IDs.
$wpide_ld_next_courses = array(
101 => array( 102 ),
102 => array( 103 ),
);
add_action( 'learndash_course_completed', function ( $data ) use ( $wpide_ld_next_courses ) {
$user_id = isset( $data['user']->ID ) ? (int) $data['user']->ID : 0;
$course_id = isset( $data['course']->ID ) ? (int) $data['course']->ID : 0;
foreach ( $wpide_ld_next_courses[ $course_id ] ?? array() as $next ) {
if ( $user_id && 'sfwd-courses' === get_post_type( $next ) && ! sfwd_lms_has_access( $next, $user_id ) ) {
ld_update_course_access( $user_id, (int) $next );
}
}
} );
Notes
Map each completed course to the course(s) that should open next. Use LearnDash's prerequisites as well if the next course must stay locked otherwise.
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.