ulgm_new_group_purchase_email_body
Filters the email body content for new group purchase notifications sent to users.
add_filter( 'ulgm_new_group_purchase_email_body', $callback, 10, 3 );
Description
Filters the body content of the email sent to a user upon a new group purchase. Modify the email's HTML or plain text to customize the message, add dynamic content, or append important information about the group purchase and the user's details.
Usage
add_filter( 'ulgm_new_group_purchase_email_body', 'your_function_name', 10, 3 );
Parameters
-
$new_group_purchase_body(mixed) - This parameter contains the HTML content of the email body that will be sent to the user upon a new group purchase.
-
$user_data(mixed) - This parameter contains the HTML content of the email body for a new group purchase, allowing for modifications to the message.
-
$group_name(mixed) - This parameter contains data about the user who made the group purchase.
Return Value
The filtered value.
Examples
/**
* Filters the body of the new group purchase email to add a custom message.
*
* This example appends a thank you message and details about the group to the
* existing email body.
*
* @param string $new_group_purchase_body The original email body content.
* @param array $user_data An array containing user data, including 'user_login', 'first_name', and 'last_name'.
* @param string $group_name The name of the group that was purchased.
*
* @return string The modified email body with the added custom message.
*/
add_filter( 'ulgm_new_group_purchase_email_body', function ( $new_group_purchase_body, $user_data, $group_name ) {
// Check if the necessary user data is available
if ( ! empty( $user_data['first_name'] ) && ! empty( $user_data['user_login'] ) ) {
$user_greeting = sprintf( 'Hello %s (%s),', $user_data['first_name'], $user_data['user_login'] );
} else {
$user_greeting = 'Hello there,';
}
// Construct the custom message
$custom_message = "nnThank you for purchasing access to the '" . esc_html( $group_name ) . "' group!n";
$custom_message .= "We're excited to have you onboard.n";
$custom_message .= "You can manage your group memberships from your account dashboard.n";
// Append the custom message to the existing email body
$modified_body = $user_greeting . "nn" . $new_group_purchase_body . $custom_message;
return $modified_body;
}, 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:954
'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 );
if ( $send_mail ) {