# LifterLMS: Learning Path With Automatic Next-Course Enrollment

> Creates a learning path by enrolling students in the next LifterLMS course automatically when they finish the previous one.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: lifterlms, enrollment, courses
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/lifterlms-course-sequence-enrollment/

## Code

```php
if ( ! function_exists( 'llms_enroll_student' ) ) {
    return;
}

// Completed course ID => next course IDs.
$wpide_llms_next_courses = array(
    101 => array( 102 ),
);

add_action( 'lifterlms_course_completed', function ( $user_id, $course_id ) use ( $wpide_llms_next_courses ) {
    foreach ( $wpide_llms_next_courses[ (int) $course_id ] ?? array() as $next ) {
        if ( 'course' === get_post_type( $next ) && ! llms_is_user_enrolled( $user_id, $next ) ) {
            llms_enroll_student( (int) $user_id, (int) $next, 'wpide_sequence' );
        }
    }
}, 10, 2 );
```

## Notes

Map each completed course to the course(s) that should follow.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LifterLMS: Learning Path With Automatic Next-Course Enrollment" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
