uo_course_certificate_email_message
Filters the email message sent when a user completes a course, allowing customization of the content.
add_filter( 'uo_course_certificate_email_message', $callback, 10, 3 );
Description
Filters the email message sent to users upon course completion. Developers can modify the entire email body, including dynamic content placeholders, to customize the notification before it's sent. This filter is applied just before the email is prepared for sending.
Usage
add_filter( 'uo_course_certificate_email_message', 'your_function_name', 10, 3 );
Parameters
-
$email_message(mixed) - This parameter contains the raw HTML content of the email message that will be sent to the user upon course completion.
-
$user(mixed) - This parameter contains the actual content of the email message that will be sent to the user.
-
$course_id(mixed) - This parameter contains the user object for which the certificate email is being generated.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the Uncanny Automations course certificate email message.
* This example adds a custom message to the end of the email if the user has completed
* the course with a score above 90%.
*
* @param string $email_message The original email message content.
* @param WP_User $user The WordPress user object.
* @param int $course_id The ID of the course the certificate is for.
* @return string The modified email message content.
*/
add_filter( 'uo_course_certificate_email_message', function( $email_message, $user, $course_id ) {
// Check if we have a valid user and course ID.
if ( ! is_a( $user, 'WP_User' ) || empty( $course_id ) || ! absint( $course_id ) ) {
return $email_message;
}
// Example: Get the user's score for this course.
// This is a placeholder; you would replace this with actual logic to retrieve the score.
// For demonstration, let's assume a function `get_user_course_score( $user->ID, $course_id )` exists.
$user_score = 0; // Default to 0 if score cannot be retrieved.
// --- IMPORTANT: Replace this with actual score retrieval logic ---
// Example of fetching course progress data which might include a score.
// This is highly dependent on how your LMS/plugin stores this data.
// For Uncanny Automations, you might look into its internal data structures or related plugins.
// A common approach is to check post meta for the user and course.
$course_progress_meta_key = '_uncanny_llms_progress_' . $course_id; // Example meta key structure
$course_progress = get_user_meta( $user->ID, $course_progress_meta_key, true );
if ( is_array( $course_progress ) && isset( $course_progress['score'] ) ) {
$user_score = absint( $course_progress['score'] );
}
// --- End of placeholder logic ---
// If the user scored above 90%, add a special message.
if ( $user_score > 90 ) {
$custom_message = "nnCongratulations on your outstanding achievement! Your score of {$user_score}% is truly impressive.";
$email_message .= $custom_message;
}
return $email_message;
}, 10, 3 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/course-completion-certificate.php:359
$email_message = self::get_settings_value( 'uncanny-course-certificate-email-body', __CLASS__ );
$non_user_body = self::get_settings_value( 'uncanny-course-certificate-non-user-email-body', __CLASS__ );
$email_subject = self::get_settings_value( 'uncanny-course-certificate-subject-line', __CLASS__ );
$email_subject_user = self::get_settings_value( 'uncanny-course-certificate-user-subject-line', __CLASS__ );
$cc_emails = self::get_settings_value( 'uncanny-course-certificate-cc-emails', __CLASS__ );
$email_subject = apply_filters( 'uo_course_certificate_email_subject', $email_subject, $user, $course_id );
$email_message = apply_filters( 'uo_course_certificate_email_message', $email_message, $user, $course_id );
$from_name = self::get_settings_value( 'uncanny-course-certificate-from-name', __CLASS__ );
$from_email = self::get_settings_value( 'uncanny-course-certificate-from-email', __CLASS__ );
$from_name = empty( $from_name ) ? get_bloginfo( 'name' ) : $from_name;
$from_email = empty( $from_email ) ? get_bloginfo( 'admin_email' ) : $from_email;
$headers = array( "From:{$from_name} <{$from_email}>" );