# 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.

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

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Congratulations Email With Certificate Link" 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/
