# LearnDash: Email the Admin When a Course Is Completed

> Emails you (or a list of addresses) whenever a student completes a LearnDash course, with the student's name and a link to their profile.

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

## Code

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

$wpide_ld_notify_emails  = array( get_option( 'admin_email' ) );
// Leave empty for all courses.
$wpide_ld_notify_courses = array();

add_action( 'learndash_course_completed', function ( $data ) use ( $wpide_ld_notify_emails, $wpide_ld_notify_courses ) {
    if ( empty( $data['user'] ) || empty( $data['course'] ) ) {
        return;
    }

    if ( $wpide_ld_notify_courses && ! in_array( (int) $data['course']->ID, $wpide_ld_notify_courses, true ) ) {
        return;
    }

    wp_mail(
        $wpide_ld_notify_emails,
        sprintf( 'Course completed: %s', get_the_title( $data['course'] ) ),
        sprintf(
            "%s (%s) completed \"%s\" on %s.\n\nProfile: %s",
            $data['user']->display_name,
            $data['user']->user_email,
            get_the_title( $data['course'] ),
            wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ),
            admin_url( 'user-edit.php?user_id=' . (int) $data['user']->ID )
        )
    );
} );
```

## Notes

Add more addresses to $wpide_ld_notify_emails, or limit it to some courses with $wpide_ld_notify_courses.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Email the Admin When a Course Is Completed" 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/
