Automattic\WooCommerce\Caches

OrderCountCacheService::update_on_order_status_changedpublicWC 1.0

Update the cache whenever an order status changes.

Метод класса: OrderCountCacheService{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$OrderCountCacheService = new OrderCountCacheService();
$OrderCountCacheService->update_on_order_status_changed( $order_id, $previous_status, $next_status, $order );
$order_id(int) (обязательный)
Order id.
$previous_status(строка) (обязательный)
The old WooCommerce order status.
$next_status(строка) (обязательный)
The new WooCommerce order status.
$order(WC_Order) (обязательный)
The order.

Код OrderCountCacheService::update_on_order_status_changed() WC 11.0.1

public function update_on_order_status_changed( $order_id, $previous_status, $next_status, $order ) {
	$order_type = $order->get_type();

	if (
		! $this->order_count_cache->is_cached( $order_type, $this->get_prefixed_status( $next_status ) ) ||
		! $this->order_count_cache->is_cached( $order_type, $this->get_prefixed_status( $previous_status ) )
	) {
		return;
	}

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

	$this->order_statuses[ $order_id ] = $next_status;
	$was_decremented                   = false !== $this->order_count_cache->decrement( $order_type, $this->get_prefixed_status( $previous_status ) );
	$this->order_count_cache->increment( $order_type, $this->get_prefixed_status( $next_status ) );

	// Set the initial order status in case this is a new order and the previous status should not be decremented.
	if ( ! isset( $this->initial_order_statuses[ $order_id ] ) && $was_decremented ) {
		$this->initial_order_statuses[ $order_id ] = $previous_status;
	}
}