Filter uncanny-toolkit-pro

uo_enable_mail_user_course_certificates

Filters whether to email course certificates to users upon completion, allowing modification of the email sending logic.

add_filter( 'uo_enable_mail_user_course_certificates', $callback, 10, 1 );

Description

Fires after a user completes a course and before their certificate email is sent. Developers can filter the `true` value to conditionally disable sending the certificate email to the user, or modify the `$email_params` array to customize the email's recipients, subject, or body.


Usage

add_filter( 'uo_enable_mail_user_course_certificates', 'your_function_name', 10, 1 );

Parameters

$email_params (mixed)
This parameter is a boolean value indicating whether to send an email to the user upon course completion certificate generation.

Return Value

The filtered value.


Examples

/**
 * Conditionally disable sending course completion certificates via email to users.
 *
 * This filter allows administrators to disable the automatic email notification
 * for course completion certificates. For example, if a custom notification
 * system is in place or if email sending is temporarily disabled.
 *
 * @param bool   $enable_mail_user Whether to enable email sending. Default is true.
 * @param array  $email_params     An array containing email parameters like 'email', 'subject', and 'msg'.
 * @return bool The modified value to control email sending.
 */
add_filter( 'uo_enable_mail_user_course_certificates', function( $enable_mail_user, $email_params ) {
    // Example: Disable emails for a specific course ID if it's present in email_params
    // In a real scenario, you might check for a specific course ID, user role,
    // or a site-wide setting.
    if ( isset( $email_params['course_id'] ) && $email_params['course_id'] === 123 ) {
        // Disable email for course ID 123
        return false;
    }

    // Example: Check a WordPress option to globally disable certificate emails
    if ( get_option( 'uo_disable_all_cert_emails' ) === 'yes' ) {
        return false;
    }

    // Otherwise, keep the default behavior (allow email sending)
    return $enable_mail_user;
}, 10, 2 );

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:453

//Sending Email To User!
		$change_content_type = apply_filters( 'uo_apply_wp_mail_content_type', true );
		if ( $change_content_type ) {
			add_filter( 'wp_mail_content_type', array( __CLASS__, 'mail_content_type' ) );
		}

		$enable_mail_user = apply_filters( 'uo_enable_mail_user_course_certificates', true, $email_params );
		if( true === $enable_mail_user ){
			wp_mail( $email_params['email'], $email_params['subject'], $email_params['msg'], $headers, $file );
		}

		if ( 'on' === $is_admin ) {
			$non_user_body       = str_ireplace( '%Group Name%', $ugroups, $non_user_body );
			$change_content_type = apply_filters( 'uo_apply_wp_mail_content_type', true );


Scroll to Top