Create Attendees
Topics
This documentation is intended to provide a comprehensive guide for programmatically creating attendees using the Events Calendar ORM. Attendees represent individual registrations for tickets and RSVPs across different e-commerce providers.
When creating attendees using the ORM, the minimum information needed is:
- The e-commerce provider-specific repository must be passed as a parameter to
tribe_attendees(). - The attendee’s full name (string)
- The attendee’s email address (string)
- The ticket/RSVP ID to add the attendee to (integer)
- The post/event ID where the ticket/RSVP is being added (integer)
Before creating attendees, you need to retrieve the ticket object and event post that you are adding the attendee to. You can do this a variety of ways, but for the purposes of this documentation, we will use the tribe_events() and tribe_tickets() methods.
If the minimum requirements are not met, the creation process will fail and return false.
RSVP Attendees (Free Tickets)
RSVP tickets are free tickets that use the repository-based creation methods. You have two approaches:
Method 1: create_attendee_for_ticket()
This method handles ticket validation, argument setup, and action triggers automatically:
$ticket_id = 123; // Your RSVP ticket ID
// Get the ticket provider and event ID
$ticket_provider = tribe_tickets_get_ticket_provider( $ticket_id );
$event_id = get_post_meta( $ticket_id, $ticket_provider->event_key, true );
// Get the proper ticket object from the provider
$ticket_object = $ticket_provider->get_ticket( $event_id, $ticket_id );
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
];
$attendee = tribe_attendees( 'rsvp' )->create_attendee_for_ticket( $ticket_object, $attendee_data );
Method 2: create()
You can use the base create() method, but you must manually update the ticket counters:
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
'ticket_id' => 123,
'post_id' => 456,
'attendee_status' => 'yes',
];
$attendee = tribe_attendees( 'rsvp' )->set_args( $attendee_data )->create();
if ( $attendee ) {
$repository = tribe_attendees( 'rsvp' );
$repository->attendee_provider->increase_ticket_sales_by( $ticket_id, 1 );
}
WooCommerce Attendees (Paid Tickets)
WooCommerce tickets are paid tickets that also use the repository-based creation methods, similar to RSVP but with the WooCommerce repository:
Method 1: create_attendee_for_ticket()
This method handles ticket validation, argument setup, and action triggers automatically:
$ticket_id = 123; // Your WooCommerce ticket ID
// Get the ticket provider and event ID
$ticket_provider = tribe_tickets_get_ticket_provider( $ticket_id );
$event_id = get_post_meta( $ticket_id, $ticket_provider->event_key, true );
// Get the proper ticket object from the provider
$ticket_object = $ticket_provider->get_ticket( $event_id, $ticket_id );
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
];
$attendee = tribe_attendees( 'woo' )->create_attendee_for_ticket( $ticket_object, $attendee_data );
Method 2: create()
You can use the base create() method, but you must manually update the ticket counters:
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
'ticket_id' => 123,
'post_id' => 456,
];
$attendee = tribe_attendees( 'woo' )->set_args( $attendee_data )->create();
if ( $attendee ) {
$repository = tribe_attendees( 'woo' );
$repository->attendee_provider->increase_ticket_sales_by( $ticket_id, 1 );
}
Required Arguments
All attendee creation requires these minimum arguments:
- Ticket Object (Tribe__Tickets__Ticket_Object): A valid ticket object instance (includes RSVPs and paid tickets)
- full_name (string): The attendee’s full name
- email (string): The attendee’s email address (valid email format)
Common Optional Arguments
These arguments are available across all provider types:
- attendee_status (string): Status of the attendee (varies by provider)
- user_id (int): WordPress user ID to associate with the attendee
- order_id (string|int): Order ID for the purchase
- order_attendee_id (int): Position of attendee within the order
- price_paid (float|int): Amount paid for the ticket
- optout (bool): Whether attendee opted out of email communications
- check_in (bool): Check-in status
- send_ticket_email (bool): Whether to send ticket email
- send_ticket_email_args (array): Email customization arguments (subject, content, from_name, from_email, headers, attachments, etc.) – Note: Email customizations are ignored when the updated Tickets Emails system is enabled (default since v5.6.0)
Tickets Commerce
Important: Tickets Commerce uses a completely different creation process than RSVP and WooCommerce tickets. Instead of directly creating attendees, Tickets Commerce creates orders first, then generates attendees from completed orders.
Tickets Commerce Creation Method
create_attendee
$ticket_id = 123; // Your Tickets Commerce ticket ID
$ticket_provider = tribe_tickets_get_ticket_provider( $ticket_id );
$event_id = get_post_meta( $ticket_id, '_tec_tickets_commerce_event', true );
$ticket_object = $ticket_provider->get_ticket( $event_id, $ticket_id );
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
];
$attendee = $ticket_provider->create_attendee( $ticket_object, $attendee_data );
What happens behind the scenes: Tickets Commerce creates a manual order, processes it through pending to completed status, then generates the attendee from the completed order. This ensures proper order relationships, payment tracking, and inventory management.
Universal Approach (Any Provider)
For code that needs to work with any ticket type, detect the provider dynamically and use the appropriate creation method:
$ticket_id = 123; // Any ticket ID
// Get the ticket provider and event relationship
$ticket_provider = tribe_tickets_get_ticket_provider( $ticket_id );
$event_id = get_post_meta( $ticket_id, $ticket_provider->event_key, true );
$attendee_data = [
'full_name' => 'John Doe',
'email' => 'john.doe@example.com',
];
// Detect provider type and use appropriate creation method
if ( $ticket_provider instanceof TEC\Tickets\Commerce\Module ) {
// Tickets Commerce (order-first creation)
$ticket_object = $ticket_provider->get_ticket( $event_id, $ticket_id );
$attendee = $ticket_provider->create_attendee( $ticket_object, $attendee_data );
} else {
// Repository-based providers (RSVP, WooCommerce, PayPal)
$ticket_object = $ticket_provider->get_ticket( $event_id, $ticket_id );
// Determine repository type
if ( $ticket_provider instanceof Tribe__Tickets__RSVP ) {
$repository = 'rsvp';
} elseif ( $ticket_provider instanceof Tribe__Tickets_Plus__Commerce__WooCommerce__Main ) {
$repository = 'woo';
} elseif ( $ticket_provider instanceof Tribe__Tickets__Commerce__PayPal__Main ) {
$repository = 'tribe-commerce';
}
$attendee = tribe_attendees( $repository )->create_attendee_for_ticket( $ticket_object, $attendee_data );
}
Quick Reference: Provider Differences
Here’s a quick comparison of the three main ticket providers and their attendee creation approaches:
RSVP (Free Tickets)
- Repository:
tribe_attendees( 'rsvp' ) - Creation Method:
create_attendee_for_ticket() - Cost: Free tickets only
- Payment: No payment processing
- Status Values: Simple yes/no RSVP responses
WooCommerce (Paid Tickets)
- Repository:
tribe_attendees( 'woo' ) - Creation Method:
create_attendee_for_ticket() - Cost: Paid tickets through WooCommerce
- Payment: Leverages WooCommerce order system
- Integration: Full WooCommerce ecosystem integration
Tickets Commerce (Paid Tickets)
- Repository: Direct provider method
- Creation Method:
$provider->create_attendee() - Cost: Paid tickets with built-in payment processing
- Payment: Integrated payment and inventory tracking
- Process: Order-first creation (order → attendees)