Filter uncanny-learndash-groups

ulgm_new_group_purchase_email_subject

Filters the subject line for new group purchase emails, allowing customization before sending.

add_filter( 'ulgm_new_group_purchase_email_subject', $callback, 10, 3 );

Description

Filters the subject line for the new group purchase confirmation email. Developers can modify the email subject to include dynamic content or personalize it for users and group purchases. This hook fires before the email is sent, allowing for complete control over the subject's appearance.


Usage

add_filter( 'ulgm_new_group_purchase_email_subject', 'your_function_name', 10, 3 );

Parameters

$new_group_purchase_subject (mixed)
This parameter holds the subject line of the email that is sent when a new group purchase is made.
$user_data (mixed)
This parameter contains the subject of the email for a new group purchase that can be filtered.
$group_name (mixed)
This parameter contains an array of data related to the user who made the group purchase.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the subject line for the new group purchase email.
 *
 * This function demonstrates how to prepend a custom string to the default
 * group purchase email subject, making it more specific to the current user.
 *
 * @param string $new_group_purchase_subject The default subject line.
 * @param array  $user_data                An array containing user data (e.g., first_name, last_name).
 * @param string $group_name               The name of the group purchased.
 *
 * @return string The modified email subject.
 */
add_filter( 'ulgm_new_group_purchase_email_subject', function( $new_group_purchase_subject, $user_data, $group_name ) {
    // Ensure user_data is an array and has a first_name key before attempting to use it.
    if ( is_array( $user_data ) && isset( $user_data['first_name'] ) ) {
        $user_first_name = sanitize_text_field( $user_data['first_name'] );
        // Prepend a personalized greeting to the subject.
        return sprintf( 'New Group Purchase for %s: %s', $user_first_name, $new_group_purchase_subject );
    }

    // If user data is not available, return the default subject.
    return $new_group_purchase_subject;
}, 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/group-management/class-group-management-helpers.php:953

'user_email' => $user_email,
			'user_login' => $user_login,
			'first_name' => $first_name,
			'last_name'  => $last_name,
		);

		$to      = apply_filters( 'ulgm_new_group_purchase_email_to', $user_email, $user_data, $group_name );
		$subject = apply_filters( 'ulgm_new_group_purchase_email_subject', $new_group_purchase_subject, $user_data, $group_name );
		$body    = apply_filters( 'ulgm_new_group_purchase_email_body', $new_group_purchase_body, $user_data, $group_name );

		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_send_new_group_purchase_email', true, $to, $subject, $group_id );


Scroll to Top