# Tutor LMS: Email the Admin When a Course Is Completed

> Emails you whenever a student completes a Tutor LMS course, with the student's name, email and the course.

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

## Code

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

$wpide_tutor_notify_emails = array( get_option( 'admin_email' ) );
// Also email the course author (the main instructor).
$wpide_tutor_notify_author = true;

add_action( 'tutor_course_complete_after', function ( $course_id, $user_id = 0 ) use ( $wpide_tutor_notify_emails, $wpide_tutor_notify_author ) {
    $user = get_userdata( $user_id ? (int) $user_id : get_current_user_id() );

    if ( ! $user ) {
        return;
    }

    $to = $wpide_tutor_notify_emails;

    if ( $wpide_tutor_notify_author ) {
        $author = get_userdata( (int) get_post_field( 'post_author', $course_id ) );
        if ( $author ) {
            $to[] = $author->user_email;
        }
    }

    wp_mail(
        array_unique( $to ),
        sprintf( 'Course completed: %s', get_the_title( $course_id ) ),
        sprintf( "%s (%s) completed \"%s\" on %s.", $user->display_name, $user->user_email, get_the_title( $course_id ), wp_date( get_option( 'date_format' ) ) )
    );
}, 10, 2 );
```

## Notes

Add more addresses to $wpide_tutor_notify_emails; the course instructor can be added with the option below.

## How to use it

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