Automattic\WooCommerce\Caches
OrderCountCacheService::update_on_order_status_changed
Update the cache whenver an order status changes.
Method of the class: OrderCountCacheService{}
No Hooks.
Returns
null. Nothing (null).
Usage
$OrderCountCacheService = new OrderCountCacheService(); $OrderCountCacheService->update_on_order_status_changed( $order_id, $previous_status, $next_status, $order );
- $order_id(int) (required)
- Order id.
- $previous_status(string) (required)
- the old WooCommerce order status.
- $next_status(string) (required)
- the new WooCommerce order status.
- $order(WC_Order) (required)
- The order.
OrderCountCacheService::update_on_order_status_changed() OrderCountCacheService::update on order status changed code WC 10.7.0
public function update_on_order_status_changed( $order_id, $previous_status, $next_status, $order ) {
if (
! $this->order_count_cache->is_cached( $order->get_type(), $this->get_prefixed_status( $next_status ) ) ||
! $this->order_count_cache->is_cached( $order->get_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 = $this->order_count_cache->decrement( $order->get_type(), $this->get_prefixed_status( $previous_status ) );
$this->order_count_cache->increment( $order->get_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;
}
}