Created
June 13, 2024 16:30
-
-
Save thecancerus/e9ff10441b2016ccc9bab1e766a48af1 to your computer and use it in GitHub Desktop.
Event ticket RSVP to Fluent CRM integration
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('event_tickets_rsvp_attendee_created', 'awesome_trigger_attendee', 11,3); | |
function awesome_trigger_attendee($attendee_id, $event_id, $order_id ){ | |
$attendee_post = get_post($attendee_id); | |
$trb = new Tribe__Tickets__RSVP(); | |
$attendee = $trb->get_attendee($attendee_id); | |
$data['first_name']=$attendee['holder_name']; | |
$data['last_name']=''; | |
$data['email']=$attendee['holder_email']; | |
$data['status']='subscribed'; | |
$contactApi = FluentCrmApi('contacts'); | |
$contact = $contactApi->createOrUpdate($data); | |
$listApi = FluentCrmApi('lists'); | |
$list_slug = sanitize_title($attendee['ticket']); | |
$lists = [ | |
[ | |
'title' => $attendee['ticket'], | |
'slug' => $list_slug, | |
'description' => 'PHPCamp Online ' | |
] | |
]; | |
$importedLists = $listApi->importBulk($lists); | |
$lists = $listApi->get(); | |
foreach ($lists as $list) { | |
if( $list->slug == $list_slug){ | |
$lid = $list->id; | |
$contact->attachLists([$lid]); | |
} | |
} | |
$year = date("Y"); | |
$tagApi = FluentCrmApi('tags'); | |
$tags = [ | |
[ | |
'title' => $year, | |
'slug' => $year, | |
'description' => '' | |
] | |
]; | |
$importedTags = $tagApi->importBulk($tags); | |
$tags = $tagApi->get(); | |
foreach ($tags as $tag) { | |
echo $tag->title; | |
if( $tag->slug == $year){ | |
$tid = $tag->id; | |
$contact->attachTags([$tid]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment