Filter uncanny-learndash-groups

ulgm_redemption_email_body

Filters the body of the redemption email before it's sent to the user.

add_filter( 'ulgm_redemption_email_body', $callback, 10, 2 );

Description

This filter allows modification of the redemption email's body content before it's sent. Developers can customize the HTML or plain text of the email, add dynamic information using the provided user data, or completely replace the default body to tailor the redemption experience.


Usage

add_filter( 'ulgm_redemption_email_body', 'your_function_name', 10, 2 );

Parameters

$redemption_template_body (mixed)
This parameter contains the HTML content of the redemption email that is being filtered.
$user_data (mixed)
This parameter contains the HTML content of the redemption email template.

Return Value

The filtered value.


Examples

// This function modifies the email body for redemption emails,
// adding a special "Thank You" message for users in the "VIP" group.
add_filter( 'ulgm_redemption_email_body', 'my_custom_redemption_email_body', 10, 2 );

function my_custom_redemption_email_body( $redemption_template_body, $user_data ) {

    // Check if the user is part of the 'VIP' group.
    // You'd need to adapt this logic based on how your plugin stores group information.
    // Assuming $user_data['groups'] is an array of group IDs or names.
    $is_vip_member = false;
    if ( ! empty( $user_data['groups'] ) && is_array( $user_data['groups'] ) ) {
        // Replace 'VIP_GROUP_ID_OR_SLUG' with the actual identifier for your VIP group.
        if ( in_array( 'VIP_GROUP_ID_OR_SLUG', $user_data['groups'] ) ) {
            $is_vip_member = true;
        }
    }

    if ( $is_vip_member ) {
        $redemption_template_body .= '<p><strong>Thank you for being a VIP member!</strong> We appreciate your continued engagement.</p>';
    }

    // You can also modify other parts of the email body here.
    // For example, let's ensure the redemption link is clearly visible.
    // Assuming '#RedemptionLink' is a placeholder in the template.
    // If your plugin doesn't use this placeholder, you'll need to find the actual way
    // to access and inject the redemption URL.
    if ( isset( $user_data['redemption_url'] ) ) {
        $redemption_url = esc_url( $user_data['redemption_url'] );
        $redemption_template_body = str_replace( '#RedemptionLink', '<a href="' . $redemption_url . '">' . __( 'Click here to redeem your item', 'your-text-domain' ) . '</a>', $redemption_template_body );
    }

    // Always return the modified (or unmodified) template body.
    return $redemption_template_body;
}

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/group-management/class-group-management-helpers.php:1266
src/classes/group-management/class-group-management-helpers.php:1671

public static function resend_redemption_email( $user_data, $redemption_template_subject, $redemption_template_body, $group_id ) {

		// Set up user data
		$user_email = $user_data['user_email'];
		$first_name = $user_data['first_name'];
		$last_name  = $user_data['last_name'];

		// Get the redemption key
		$redemption_key = $user_data['key'];

		// Filter #EmailEncoded variable
		$redemption_template_subject = str_ireplace( '#EmailEncoded', urlencode( $user_email ), $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#EmailEncoded', urlencode( $user_email ), $redemption_template_body );

		// Filter #email variable
		$redemption_template_subject = str_ireplace( '#Email', $user_email, $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#Email', $user_email, $redemption_template_body );

		// Filter #first_name variable
		$redemption_template_subject = str_ireplace( '#FirstName', $first_name, $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#FirstName', $first_name, $redemption_template_body );

		// Filter #last_name variable
		$redemption_template_subject = str_ireplace( '#LastName', $last_name, $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#LastName', $last_name, $redemption_template_body );

		// Filter #redemption_key variable
		$redemption_template_subject = str_ireplace( '#RedemptionKey', $redemption_key, $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#RedemptionKey', $redemption_key, $redemption_template_body );

		// Filter #SiteUrl variable
		$redemption_template_subject = str_ireplace( '#SiteUrl', site_url(), $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#SiteUrl', site_url(), $redemption_template_body );

		// Filter #LoginUrl variable
		$redemption_template_subject = str_ireplace( '#LoginUrl', wp_login_url(), $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#LoginUrl', wp_login_url(), $redemption_template_body );

		// Filter #GroupLeaderInfo variable
		$redemption_template_subject = str_ireplace( '#GroupLeaderInfo', self::get_group_leader_info( $group_id ), $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#GroupLeaderInfo', self::get_group_leader_info( $group_id ), $redemption_template_body );

		// Filter #Courses variable
		$redemption_template_subject = str_ireplace( '#Courses', self::get_group_courses( $group_id ), $redemption_template_subject );
		$redemption_template_body    = str_ireplace( '#Courses', self::get_group_courses( $group_id ), $redemption_template_body );

		// Remove escaped apostrophes
		$redemption_template_subject = str_replace( "'", "'", $redemption_template_subject );
		$redemption_template_body    = str_replace( "'", "'", $redemption_template_body );

		$to      = apply_filters( 'ulgm_redemption_email_to', $user_email, $user_data );
		$subject = apply_filters( 'ulgm_redemption_email_subject', $redemption_template_subject, $user_data );
		$body    = apply_filters( 'ulgm_redemption_email_body', $redemption_template_body, $user_data );

		if ( ! class_exists( 'WP_Better_Emails' ) || ( false === preg_match( '/<DOCTYPE/', $body ) && false === preg_match( '/<head>/', $body ) ) ) {
			$body = wpautop( $body );
		}
		$send_mail = apply_filters( 'ulgm_maybe_resend_redemption_email', true, $to, $subject, $group_id );
		if ( $send_mail ) {
			$redemption_email = SharedFunctions::wp_mail( $to, $subject, $body, self::get_headers() );

			//If the mail is successful let a a fake user and group meta
			if ( is_wp_error( $redemption_email ) ) {
				return false;
			}
		}

		return true;
	}


Scroll to Top