Created
October 1, 2025 10:40
-
-
Save ahsannayem/274e02e696ab5bc85771e5165957da04 to your computer and use it in GitHub Desktop.
Add tag when Status change from Pending to Subscrived
This file contains hidden or 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_subscribed', function ($subscriber, $oldStatus) { | |
// Only act when moving from pending to subscribed | |
if ($oldStatus !== 'pending' || !$subscriber || empty($subscriber->id)) { | |
return; | |
} | |
$tagName = 'Onboarding'; // change as needed | |
// Ensure the tag exists (FluentCRM model API) | |
if (class_exists('\FluentCrm\App\Models\Tag')) { | |
$tag = \FluentCrm\App\Models\Tag::firstOrCreate( | |
['title' => $tagName], | |
['slug' => sanitize_title($tagName)] | |
); | |
if ($tag && !empty($tag->id)) { | |
// Attach tag to the subscriber | |
$subscriber->attachTags([$tag->id]); | |
} | |
} | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment