# 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.

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

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Enroll in the Next Course After Completing One" 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/
