Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/9801602c1a0555c4d27ccf2848350bec to your computer and use it in GitHub Desktop.
Save sc0ttkclark/9801602c1a0555c4d27ccf2848350bec to your computer and use it in GitHub Desktop.
Event Tickets Attendees ORM examples
<?php
/*
* Get a list of attendees.
*/
// Set the provider. This can be default (all attendees of any type), tribe-commerce, rsvp, woo, or edd.
$provider = 'default';
// Get the ORM object set up.
$attendees_orm = tribe_attendees( $provider );
// Specify how many to return, this is always recommended to be set to anything but -1 for unlimited.
$attendees_orm->per_page( 50 );
// Filter attendees by a specific event/post. This can be an array of IDs or just one ID.
$attendees_orm->by( 'event', 123 );
// Get a list of attendee IDs.
$attendee_ids = $attendees_orm->get_ids();
// Get a list of attendee post objects.
$attendees = $attendees_orm->all();
<?php
/*
* Create a new attendee.
*/
// Set the provider. This *needs* to be set to a specific provider: tribe-commerce, rsvp, woo, or edd.
$provider = 'rsvp';
// Get the ORM object set up.
$attendees_orm = tribe_attendees( $provider );
// Set the ticket, this can be the ticket ID or the actual ticket object.
$ticket = 123;
// Set the attendee data to be saved.
$attendee_data = [
'full_name' => 'John Smith',
'email' => 'john@smith.com',
];
// You can also send the attendee their ticket to their email. The default is false, no email will be sent.
$attendee_data['send_ticket_email'] = true;
// This will create the attendee. It will return the post object if successful, or false if there was a problem.
$new_attendee = $attendees_orm->create_attendee_for_ticket( $ticket, $attendee_data );
<?php
/*
* Update an attendee.
*/
// Set the provider. This *needs* to be set to a specific provider: tribe-commerce, rsvp, woo, or edd.
$provider = 'rsvp';
// Get the ORM object set up.
$attendees_orm = tribe_attendees( $provider );
// Set the attendee data to be updated.
$attendee_data = [
'attendee_id' => 123,
'full_name' => 'Johnny Smith',
'email' => 'johnny@smith.com',
];
// You can also send the attendee their updated ticket to their email. The default is false, no email will be sent.
$attendee_data['send_ticket_email'] = true;
// This will update the attendee. It will return an array of IDs that were saved [ 123 => true ].
$results = $attendees_orm->update_attendee( $attendee_data );
<?php
/*
* Delete an attendee.
*/
// Set the provider. This can be default (all attendees of any type), tribe-commerce, rsvp, woo, or edd.
$provider = 'default';
// Get the ORM object set up.
/** @var Tribe__Tickets__Attendee_Repository $attendees_orm */
$attendees_orm = tribe_attendees( $provider );
// Specify how many to return, this is always recommended to be set to anything but -1 for unlimited.
$attendees_orm->per_page( 50 );
// Filter attendees by a specific event/post. This can be an array of IDs or just one ID.
$attendees_orm->by( 'event', 123 );
// OR only get specific attendee(s). This can be an array of IDs or just one ID.
$attendees_orm->by( 'id', 123 );
// Delete all of the attendees that match.
$attendees_orm->delete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment