# LearnDash: Email the Admin About New Enrollments

> Sends you an email whenever a user is given access to a LearnDash course, whether through purchase, a group or manual enrollment.

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

## Code

```php
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
    return;
}

$wpide_ld_enroll_courses = array();

add_action( 'learndash_update_course_access', function ( $user_id, $course_id, $access_list = null, $remove = false ) use ( $wpide_ld_enroll_courses ) {
    if ( $remove || ( $wpide_ld_enroll_courses && ! in_array( (int) $course_id, $wpide_ld_enroll_courses, true ) ) ) {
        return;
    }

    $user = get_userdata( $user_id );

    if ( ! $user ) {
        return;
    }

    wp_mail(
        get_option( 'admin_email' ),
        sprintf( 'New enrollment: %s', get_the_title( $course_id ) ),
        sprintf( "%s (%s) was enrolled in \"%s\".\n\nProfile: %s", $user->display_name, $user->user_email, get_the_title( $course_id ), admin_url( 'user-edit.php?user_id=' . (int) $user_id ) )
    );
}, 10, 4 );
```

## Notes

Removals are not reported. Limit it to some courses with $wpide_ld_enroll_courses.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Email the Admin About New Enrollments" 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/
