Tribe__Tickets_Plus__Commerce__WooCommerce__Global_Stock::cart_check_stock()

Looks at the item quantities in the cart and ensures that they are not “out of bounds” in the case of global stock tickets.

Amongst other things, this should properly support scenarios where the cart contains:

A) Tickets which belong to an event with global stock, but do not themselves
   draw on the global stock

B) Multiple tickets utilizing global stock, but belonging to different events
   (ie, some tickets from Event A and some tickets from Event B)

Expects to be called when the woocommerce_check_cart_items action fires, which typically occurs both when the cart is updated and when the cart is submitted via the checkout page.


Source

File: src/Tribe/Commerce/WooCommerce/Global_Stock.php

	public function cart_check_stock() {
		$insufficient_stock = array();

		// Look at the requested totals for each globally stocked event we're interested in and ensure
		// the quantities don't exceed
		foreach ( $this->cart_get_global_stock_quantities() as $event_id => $quantity ) {
			$global_stock = new Tribe__Tickets__Global_Stock( $event_id );

			if ( $quantity > $global_stock->get_stock_level() ) {
				$insufficient_stock[] = get_the_title( $event_id );
			}
		}

		// If we detect out-of-stock scenarios re globally stocked tickets, flag a warning
		if ( ! empty( $insufficient_stock ) ) {
			$this->cart_flag_global_stock_error( $insufficient_stock );
		}
	}