Created
August 4, 2021 22:53
-
-
Save rafiahmedd/21c2f3f71aecd965878c4b52f4c9302c to your computer and use it in GitHub Desktop.
Email to Admin After User Unsubscribe From CRM With Unsubscribe Reason
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('fluentcrm_subscriber_status_to_unsubscribed', 'emailAfterUnsubscribed', 10, 2); | |
function emailAfterUnsubscribed($subscriber, $oldStatus){ | |
$req = FluentCrm('request'); | |
$reason = sanitize_text_field($req->get('reason')); | |
if ($reason == 'other') { | |
if ($otherReason = $req->get('other_reason')) { | |
$reason = sanitize_text_field($otherReason); | |
} | |
} else if($reason){ | |
if ( method_exists('ExternalPages', 'unsubscribeReasons' ) ) { | |
$reasons = ExternalPages::unsubscribeReasons(); | |
if (isset($reasons[$reason])) { | |
$reason = sanitize_text_field($reasons[$reason]); | |
} | |
} | |
} | |
$email = $subscriber->email; | |
$first_name = $subscriber->first_name; | |
$to = 'admin@mail.com'; //Your mail id you call also email to the user | |
$subject = $first_name.' unsubscribed form your site.'; | |
$message = $email.' unsubscribed the reason behind it is: '.$reason; | |
return wp_mail( $to, $subject, $message ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment