LearnDash: Congratulations Email With Certificate Link
Sends students a friendly congratulations email when they complete a course, including a link to download their certificate when the course has one.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
$wpide_ld_congrats_subject = 'Congratulations on finishing %2$s!';
$wpide_ld_congrats_message = "Hi %1\$s,\n\nWell done, you have completed \"%2\$s\".";
add_action( 'learndash_course_completed', function ( $data ) use ( $wpide_ld_congrats_subject, $wpide_ld_congrats_message ) {
if ( empty( $data['user'] ) || empty( $data['course'] ) ) {
return;
}
$user = $data['user'];
$course = $data['course'];
$name = $user->first_name ? $user->first_name : $user->display_name;
$title = get_the_title( $course );
$body = sprintf( $wpide_ld_congrats_message, $name, $title );
$cert = learndash_get_course_certificate_link( $course->ID, $user->ID );
if ( $cert ) {
$body .= "\n\nDownload your certificate:\n" . $cert;
}
$body .= "\n\nSee you in the next course!\n" . get_bloginfo( 'name' );
wp_mail( $user->user_email, sprintf( $wpide_ld_congrats_subject, $name, $title ), $body );
} );
Notes
Edit the subject and message at the top; %1$s is the student's first name and %2$s the course title.
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.