ulgm_maybe_send_new_group_purchase_email
Filters whether to send a new group purchase email, allowing modification of recipient, subject, and group ID.
add_filter( 'ulgm_maybe_send_new_group_purchase_email', $callback, 10, 3 );
Description
Filters whether a new group purchase email should be sent. Developers can return `false` to prevent the email from being sent. This filter is applied before the email content is processed, allowing for conditional sending based on various factors.
Usage
add_filter( 'ulgm_maybe_send_new_group_purchase_email', 'your_function_name', 10, 3 );
Parameters
-
$to(mixed) - This parameter represents a boolean value indicating whether the email should be sent.
-
$subject(mixed) - This parameter holds the recipient(s) of the email.
-
$group_id(mixed) - This parameter holds the subject line for the new group purchase email.
Return Value
The filtered value.
Examples
<?php
/**
* Example of using the ulgm_maybe_send_new_group_purchase_email filter.
* This example prevents sending the email if the group ID is 'test-group-123'.
*/
add_filter( 'ulgm_maybe_send_new_group_purchase_email', function( $should_send, $to, $subject, $group_id ) {
// Prevent sending email for a specific test group ID.
if ( 'test-group-123' === $group_id ) {
// Return false to indicate that the email should NOT be sent.
return false;
}
// If it's not the test group, allow the email to be sent by returning true.
return $should_send;
}, 10, 4 );
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:960
$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 ) {
$mail_sent = SharedFunctions::wp_mail( $to, $subject, $body, self::get_headers() );
return $mail_sent;
} else {
return true;
}