Module::create_attendee( Tribe__Tickets__Ticket_Object|int $ticket, array $attendee_data )
Create an attendee for the Commerce provider from a ticket.
Contents
Parameters
- $ticket
-
(Tribe__Tickets__Ticket_Object|int) (Required) Ticket object or ID to create the attendee for.
- $attendee_data
-
(array) (Required) Attendee data to create from.
Return
(WP_Post|WP_Error|false) The new post object or false if we can't resolve to a Ticket object. WP_Error if modifying status fails
Source
File: src/Tickets/Commerce/Module.php
public function create_attendee( $ticket, $attendee_data ) {
// Get the ticket object from the ID.
if ( is_numeric( $ticket ) ) {
$ticket = $this->get_ticket( 0, (int) $ticket );
}
// If the ticket is not valid, stop creating the attendee.
if ( ! $ticket instanceof \Tribe__Tickets__Ticket_Object ) {
return false;
}
$extra = [];
$extra['attendees'] = [
1 => [
'meta' => Arr::get( $attendee_data, 'attendee_meta', [] )
]
];
$extra['optout'] = ! Arr::get( $attendee_data, 'send_ticket_email', true );
$extra['iac'] = false;
// The Manual Order takes the same format as the cart items.
$items = [
$ticket->ID => [
'ticket_id' => $ticket->ID,
'quantity' => 1,
'extra' => $extra,
]
];
$purchaser = [
'full_name' => $attendee_data['full_name'],
'email' => $attendee_data['email'],
// By default user ID is zero here.
'user_id' => 0,
];
$order = tribe( Gateways\Manual\Order::class )->create( $items, $purchaser );
/**
* For now we need to make sure we move to pending before completed.
*
* @todo @backend when an order is moved into completed they need to update to pending first.
* likely we should have this be developed by implementing a dependent status.
*/
$updated = tribe( Order::class )->modify_status( $order->ID, 'pending' );
if ( is_wp_error( $updated ) ) {
return $updated;
}
$updated = tribe( Order::class )->modify_status( $order->ID, 'completed' );
if ( is_wp_error( $updated ) ) {
return $updated;
}
$attendee = tec_tc_attendees()->by( 'order_id', $order->ID )->first();
return $attendee;
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |