# Tutor LMS: Enroll New Users in Free Courses

> Enrolls every newly registered user in the Tutor LMS courses you choose, such as a free getting-started course.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: tutor, enrollment, registration
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/tutor-auto-enroll-new-users/

## Code

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

// Course IDs.
$wpide_tutor_starter_courses = array( 123 );

add_action( 'user_register', function ( $user_id ) use ( $wpide_tutor_starter_courses ) {
    foreach ( $wpide_tutor_starter_courses as $course_id ) {
        if ( get_post_type( $course_id ) === tutor()->course_post_type && ! tutor_utils()->is_enrolled( $course_id, $user_id ) ) {
            tutor_utils()->do_enroll( (int) $course_id, 0, (int) $user_id );
        }
    }
}, 20 );
```

## Notes

Use free courses here; paid courses should be enrolled through their checkout.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tutor LMS: Enroll New Users in Free Courses" 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/
