What is a good solution to not sending comment subscription notifications to people who subscribed to notifications more than (for example) 6 months ago?
I have some posts which still get comments after months/years and people who subscribed to comments way back sometimes think the email notification is spam because they don't remember commenting or lost interest long ago.
Is there a filter that fires before comment subscription emails are sent, for example, that would allow me to check the age of the subscription and prevent the email being sent?
Or a filter that fires when a comment subscription is added that I could hook into and delete all comment subs older than X months?
Thanks 🙂
Hi @salubritas,
Below is provided the hook you should use:
wpdiscuz_email_notification
You should find the ID of the subscription(this is the second parametre), in the parameters of this hook. Then check out it in the wp_wc_comments_subscription table. If the subscribtion_type is a "comment" you should prevent the email sending.
Or a filter that fires when a comment subscription is added that I could hook into and delete all comment subs older than X months?
Also, there is a data type in the parameters you can use it to delete the old comments( older than 6 months).
Thank you Elvina, I will look into that.
This seems to be working how I want:
// wpDiscuz: don't send comment subs notifications for subscriptions older than 6 months
function wr_wpdiscuz_email_notification($emailSender, $emailData, $comment) {
$sub_id = $emailData['id'];
global $wpdb;
$sql = $wpdb->prepare(
"SELECT COUNT(*) FROM wp_wc_comments_subscription where id = %d
AND DATE_ADD(subscription_date, INTERVAL 6 MONTH) > CURDATE()",
$sub_id
);
$sendMail = $wpdb->get_var($sql);
return $sendMail;
}
add_filter('wpdiscuz_email_notification', 'wr_wpdiscuz_email_notification', 10, 3);