Filter uncanny-learndash-groups

ulgm_new_group_purchase_email_to

Filters the recipient email address for new group purchase confirmation emails before they are sent.

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

Description

Filters the recipient email address for the "new group purchase" notification. Modify this hook to send the email to a different user or multiple recipients, enabling custom notification routing or administrative alerts.


Usage

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

Parameters

$user_email (mixed)
This parameter contains the email address of the user who made the group purchase.
$user_data (mixed)
This parameter contains the email address of the user who made the group purchase.
$group_name (mixed)
This parameter contains an array of the user's data.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the ulgm_new_group_purchase_email_to filter.
 * This example modifies the recipient email address to add a specific user's email
 * as a secondary recipient when a new group purchase is made.
 *
 * @param string $user_email   The original recipient email address.
 * @param array  $user_data    An array containing user data. Expected keys: 'user_id', 'user_email', 'user_login', 'first_name', 'last_name'.
 * @param string $group_name   The name of the group purchased.
 * @return string The modified recipient email address (or array of addresses).
 */
add_filter( 'ulgm_new_group_purchase_email_to', function( $user_email, $user_data, $group_name ) {
    // Define a specific email address to always CC on new group purchase notifications.
    $cc_admin_email = '[email protected]';

    // Check if the $user_email is already an array (e.g., for multiple recipients).
    if ( is_array( $user_email ) ) {
        // Add the CC email to the existing array if it's not already there.
        if ( ! in_array( $cc_admin_email, $user_email ) ) {
            $user_email[] = $cc_admin_email;
        }
    } else {
        // If $user_email is a single string, create an array with the original and CC email.
        if ( $user_email !== $cc_admin_email ) {
            $user_email = array( $user_email, $cc_admin_email );
        }
    }

    // You could also conditionally add the CC based on the group name or user data.
    // For example, to only CC for a specific group:
    // if ( 'Premium Membership Group' === $group_name ) {
    //     if ( is_array( $user_email ) ) {
    //         if ( ! in_array( $cc_admin_email, $user_email ) ) {
    //             $user_email[] = $cc_admin_email;
    //         }
    //     } else {
    //         if ( $user_email !== $cc_admin_email ) {
    //             $user_email = array( $user_email, $cc_admin_email );
    //         }
    //     }
    // }

    return $user_email;
}, 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:952

'user_id'    => $user_id,
			'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 );
		}


Scroll to Top