<?php
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
$track->subscriber->addToBlacklist("Your message here...");
});
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
$exists = EmailBlacklist::model()->findByAttributes(['email' => $track->subscriber->email]);
if (!empty($exists)) {
return;
}
$model = new EmailBlacklist();
$model->email = $track->subscriber->email;
$model->subscriber_id = $track->subscriber_id;
$model->reason = 'Add your message here';
$model->save(false);
$track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) {
$exists = CustomerEmailBlacklist::model()->findByAttributes([
'email' => $track->subscriber->email,
'customer_id' => $track->campaign->customer_id,
]);
if (!empty($exists)) {
return;
}
$model = new CustomerEmailBlacklist();
$model->email = $track->subscriber->email;
$model->customer_id = $track->campaign->customer_id;
$model->reason = 'Add your message here';
$model->save(false);
$track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED);
});
This works perfect. Is there a way for me to copy the Hard Bounces from the customer blacklist to master blacklist?@jonathanm841 - You could potentially make use of the per-customer email blacklist, so instead of injecting the email into the global backlist, you add it in the customer blacklist.
To do this, first enable per-customer email blacklist from Backend > Settings > Customers > Lists > Use own blacklist (same in customer group).
Then modify the code as:
PHP:Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) { $exists = CustomerEmailBlacklist::model()->findByAttributes([ 'email' => $track->subscriber->email, 'customer_id' => $track->campaign->customer_id, ]); if (!empty($exists)) { return; } $model = new CustomerEmailBlacklist(); $model->email = $track->subscriber->email; $model->customer_id = $track->campaign->customer_id; $model->reason = 'Add your message here'; $model->save(false); $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED); });
Hard bounces are inserted directly in the global blacklist not in the customer blacklist, so you should not need to change anything else.to copy the Hard Bounces from the customer blacklist to master blacklist?
Will this be added in some ways more natively within one of the next updates? So we can decide what type of behavior a list unsubscribe should be doing.@jonathanm841 - You could potentially make use of the per-customer email blacklist, so instead of injecting the email into the global backlist, you add it in the customer blacklist.
To do this, first enable per-customer email blacklist from Backend > Settings > Customers > Lists > Use own blacklist (same in customer group).
Then modify the code as:
PHP:Yii::app()->hooks->addAction('frontend_lists_after_track_campaign_unsubscribe', function($controller, CampaignTrackUnsubscribe $track) { $exists = CustomerEmailBlacklist::model()->findByAttributes([ 'email' => $track->subscriber->email, 'customer_id' => $track->campaign->customer_id, ]); if (!empty($exists)) { return; } $model = new CustomerEmailBlacklist(); $model->email = $track->subscriber->email; $model->customer_id = $track->campaign->customer_id; $model->reason = 'Add your message here'; $model->save(false); $track->subscriber->saveStatus(ListSubscriber::STATUS_BLACKLISTED); });
We do not plan to change the way the app unsubscribe process works, so it will not change in the app.Will this be added in some ways more natively within one of the next updates?
Great! What I was referring to is to have an option in the settings to decide the behavior of when someone unsubscribe.We do not plan to change the way the app unsubscribe process works, so it will not change in the app.
However, the changes you applied will be safe for upgrades.