ulgm_do_not_send_redemption_email
Filters whether to send a redemption email, allowing you to conditionally prevent it based on user and group data.
add_filter( 'ulgm_do_not_send_redemption_email', $callback, 10, 3 );
Description
Fires before sending a redemption email for a group. Developers can use this filter to prevent the email from being sent by returning `true`. The filter receives user and group data, allowing conditional logic based on specific users or groups.
Usage
add_filter( 'ulgm_do_not_send_redemption_email', 'your_function_name', 10, 3 );
Parameters
-
$do_not_send_emails(mixed) - This parameter determines whether redemption emails should be sent.
-
$user_data(mixed) - This parameter is a boolean value that, if set to `true`, prevents the redemption email from being sent.
-
$group_id(mixed) - This parameter contains the user's data, which can be used to dynamically personalize the redemption email.
Return Value
The filtered value.
Examples
/**
* Example of how to use the 'ulgm_do_not_send_redemption_email' filter hook.
* This function prevents the redemption email from being sent for a specific user
* if they are a premium member of a certain group.
*
* @param bool $do_not_send_emails The current value of whether to send the email.
* @param WP_User $user_data The WP_User object of the user.
* @param int $group_id The ID of the group.
*
* @return bool Returns true to prevent the email from being sent, false otherwise.
*/
function my_custom_prevent_redemption_email( $do_not_send_emails, $user_data, $group_id ) {
// Check if the user is a premium member of the group.
// This is a hypothetical check; you'd replace 'my_plugin_is_premium_member'
// with your actual function or logic to determine premium membership.
if ( function_exists( 'my_plugin_is_premium_member' ) && my_plugin_is_premium_member( $user_data->ID, $group_id ) ) {
// If they are a premium member, do not send the redemption email.
return true;
}
// Otherwise, let the default logic decide (which is to send the email unless
// other filters prevent it).
return $do_not_send_emails;
}
add_filter( 'ulgm_do_not_send_redemption_email', 'my_custom_prevent_redemption_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:1646
$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 );
$do_not_send_emails = apply_filters( 'ulgm_do_not_send_redemption_email', $do_not_send_emails, $user_data, $group_id );
if ( $do_not_send_emails ) {
if ( ! $counter ) {
$data['message'] = __( 'User has been added.', 'uncanny-learndash-groups' );
SharedFunctions::delete_transient( null, $group_id );
wp_send_json_success( $data );