ulgm_redemption_email_sent
Fires after a user's redemption email has been successfully sent.
add_action( 'ulgm_redemption_email_sent', $callback, 10, 2 );
Description
Fires after a group redemption email has been successfully sent. Developers can use this hook to perform actions following email delivery, such as logging the event or triggering further notifications. It receives the user data and group ID associated with the redemption.
Usage
add_action( 'ulgm_redemption_email_sent', 'your_function_name', 10, 2 );
Parameters
-
$user_data(mixed) - This parameter contains the user data associated with the redemption, likely including their ID, username, and email address.
-
$group_id(mixed) - This parameter contains the data of the user who redeemed the item or membership.
Examples
/**
* Example function to hook into ulgm_redemption_email_sent.
* This function logs information about the redemption email being sent.
*
* @param mixed $user_data The data of the user who received the redemption email.
* @param mixed $group_id The ID of the group associated with the redemption.
*/
function my_ulgm_log_redemption_email_sent( $user_data, $group_id ) {
// Check if the user_data is an array and contains an 'email' key.
if ( is_array( $user_data ) && isset( $user_data['email'] ) ) {
$user_email = $user_data['email'];
} elseif ( is_object( $user_data ) && property_exists( $user_data, 'user_email' ) ) {
$user_email = $user_data->user_email;
} else {
// Fallback if user email cannot be determined.
$user_email = 'Unknown User';
}
// Log a message to the WordPress debug log.
// You can replace this with any other action, like updating a meta field,
// sending a notification to an admin, etc.
error_log( sprintf(
'ULGM Redemption Email Sent: User %s received redemption for group ID %s.',
$user_email,
$group_id
) );
}
// Hook the function to the 'ulgm_redemption_email_sent' action.
// The second parameter '2' specifies that our function accepts 2 arguments.
add_action( 'ulgm_redemption_email_sent', 'my_ulgm_log_redemption_email_sent', 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/group-management/class-group-management-helpers.php:1678
$body = apply_filters( 'ulgm_redemption_email_body', $redemption_template_body, $user_data, $group_id );
if ( ! class_exists( 'WP_Better_Emails' ) || ( false === preg_match( '/<DOCTYPE/', $body ) && false === preg_match( '/<head>/', $body ) ) ) {
$body = wpautop( $body );
}
$send_email = apply_filters( 'ulgm_maybe_send_redemption_email', true, $to, $subject );
do_action( 'ulgm_redemption_email_sent', $user_data, $group_id );
if ( $send_email && 'yes' === get_option( 'ulgm_send_code_redemption_email', 'yes' ) ) {
$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 ) ) {