Tribe__Tickets_Plus__Commerce__EDD__Main::checkout_errors()
Ensure out of stock tickets cannot be purchased even if they manage to get added to the cart
Source
File: src/Tribe/Commerce/EDD/Main.php
public function checkout_errors() {
$this->global_stock()->check_stock();
//run setup to prevent no statuses on ajax checkout
tribe( 'tickets.status' )->setup();
foreach ( (array) edd_get_cart_contents() as $item ) {
$remaining = $this->stock_control->available_units( $item['id'] );
// We have to append the item IDs otherwise if we have multiple errors of the same type one will overwrite
// the other
if ( ! $remaining ) {
edd_set_error( 'no_stock_' . $item['id'], sprintf( __( '%s ticket is sold out', 'event-tickets-plus' ), get_the_title( $item['id'] ) ) );
} elseif ( self::UNLIMITED !== $remaining && $item['quantity'] > $remaining ) {
edd_set_error( 'insufficient_stock_' . $item['id'], sprintf( __( 'Sorry! Only %d tickets remaining for %s', 'event-tickets-plus' ), $remaining, get_the_title( $item['id'] ) ) );
}
}
}