Automattic\WooCommerce\Caches

OrderCountCacheService::update_on_new_orderpublicWC 1.0

Update the cache when a new order is made.

Method of the class: OrderCountCacheService{}

No Hooks.

Returns

null. Nothing (null).

Usage

$OrderCountCacheService = new OrderCountCacheService();
$OrderCountCacheService->update_on_new_order( $order_id, $order );
$order_id(int) (required)
Order id.
$order(WC_Order) (required)
The order.

OrderCountCacheService::update_on_new_order() code WC 10.7.0

public function update_on_new_order( $order_id, $order ) {
	if ( ! $this->order_count_cache->is_cached( $order->get_type(), $this->get_prefixed_status( $order->get_status() ) ) ) {
		return;
	}

	// If the order status was updated, we need to increment the order count cache for the
	// initial status that was errantly decremented on order status change.
	if ( isset( $this->initial_order_statuses[ $order_id ] ) ) {
		$this->order_count_cache->increment( $order->get_type(), $this->get_prefixed_status( $this->initial_order_statuses[ $order_id ] ) );
	}

	// If the order status count has already been incremented, we can skip incrementing it again.
	if ( isset( $this->order_statuses[ $order->get_id() ] ) && $this->order_statuses[ $order->get_id() ] === $order->get_status() ) {
		return;
	}

	$this->order_statuses[ $order_id ] = $order->get_status();
	$this->order_count_cache->increment( $order->get_type(), $this->get_prefixed_status( $order->get_status() ) );
}