Tribe__Tickets__RSVP::generate_tickets( int|null $post_id = null, boolean $redirect = true )
Generate and store all the attendees information for a new order.
Contents
Parameters
- $post_id
-
(int|null) (Optional) Post ID for ticket, null to use current post ID.
Default value: null
- $redirect
-
(boolean) (Optional) Whether to redirect on error.
Default value: true
Return
(array|WP_Error) List of attendee ID(s) generated, or WP_Error if there was a problem.
Source
File: src/Tribe/RSVP.php
public function generate_tickets() {
if ( empty( $_POST['tickets_process'] ) || empty( $_POST['attendee'] ) || empty( $_POST['product_id'] ) ) {
return;
}
$has_tickets = false;
$post_id = get_the_ID();
/**
* RSVP specific action fired just before a RSVP-driven attendee tickets for an order are generated
*
* @param $data $_POST Parameters comes from RSVP Form
*/
do_action( 'tribe_tickets_rsvp_before_order_processing', $_POST );
// Parse the details submitted for the RSVP
$attendee_details = $this->parse_attendee_details();
// If there are details missing, we return to the event page with the rsvp_error
if ( false === $attendee_details ) {
$url = get_permalink();
$url = add_query_arg( 'rsvp_error', 1, $url );
wp_redirect( esc_url_raw( $url ) );
tribe_exit();
}
// Iterate over each product
foreach ( (array) $_POST['product_id'] as $product_id ) {
if ( ! $ticket_qty = $this->parse_ticket_quantity( $product_id ) ) {
// if there were no RSVP tickets for the product added to the cart, continue
continue;
}
$has_tickets |= $this->generate_tickets_for( $product_id, $ticket_qty, $attendee_details );
}
$order_id = $attendee_details['order_id'];
$attendee_order_status = $attendee_details['order_status'];
/**
* Fires when an RSVP attendee tickets have been generated.
*
* @param int $order_id ID of the RSVP order
* @param int $post_id ID of the post the order was placed for
* @param string $attendee_order_status status if the user indicated they will attend
*/
do_action( 'event_tickets_rsvp_tickets_generated', $order_id, $post_id, $attendee_order_status );
$send_mail_stati = tribe( 'tickets.status' )->get_statuses_by_action( 'attendee_dispatch', 'rsvp' );
/**
* Filters whether a confirmation email should be sent or not for RSVP tickets.
*
* This applies to attendance and non attendance emails.
*
* @param bool $send_mail Defaults to `true`.
*/
$send_mail = apply_filters( 'tribe_tickets_rsvp_send_mail', true );
if ( $send_mail ) {
/**
* Filters the attendee order stati that should trigger an attendance confirmation.
*
* Any attendee order status not listed here will trigger a non attendance email.
*
* @param array $send_mail_stati An array of default stati triggering an attendance email.
* @param int $order_id ID of the RSVP order
* @param int $post_id ID of the post the order was placed for
* @param string $attendee_order_status status if the user indicated they will attend
*/
$send_mail_stati = apply_filters(
'tribe_tickets_rsvp_send_mail_stati', $send_mail_stati, $order_id, $post_id, $attendee_order_status
);
// No point sending tickets if their current intention is not to attend
if ( $has_tickets && in_array( $attendee_order_status, $send_mail_stati ) ) {
$this->send_tickets_email( $order_id, $post_id );
} elseif ( $has_tickets ) {
$this->send_non_attendance_confirmation( $order_id, $post_id );
}
}
// Redirect to the same page to prevent double purchase on refresh
if ( ! empty( $post_id ) ) {
$url = get_permalink( $post_id );
$url = add_query_arg( 'rsvp_sent', 1, $url );
wp_redirect( esc_url_raw( $url ) );
tribe_exit();
}
}