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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.