# LifterLMS: Enroll New Users in Starter Courses

> Enrolls every newly registered user in the LifterLMS courses or memberships you choose, such as a free welcome course.

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

## Code

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

// Course or membership IDs.
$wpide_llms_starter_products = array( 123 );

add_action( 'user_register', function ( $user_id ) use ( $wpide_llms_starter_products ) {
    foreach ( $wpide_llms_starter_products as $product_id ) {
        if ( in_array( get_post_type( $product_id ), array( 'course', 'llms_membership' ), true ) && ! llms_is_user_enrolled( $user_id, $product_id ) ) {
            llms_enroll_student( $user_id, (int) $product_id, 'wpide_new_user' );
        }
    }
}, 20 );
```

## Notes

Add course or membership IDs to $wpide_llms_starter_products. Existing users are not enrolled.

## How to use it

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