Automattic\WooCommerce\Caches

OrderCountCache::ensure_statuses_for_typeprivateWC 1.0

Adds the given statuses to the cached statuses array for the order type if they are not already stored.

Method of the class: OrderCountCache{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->ensure_statuses_for_type( $order_type, $order_statuses );
$order_type(string) (required)
The order type to save with.
$order_statuses(string[]) (required)
One or more normalised statuses to add.

OrderCountCache::ensure_statuses_for_type() code WC 10.7.0

private function ensure_statuses_for_type( string $order_type, array $order_statuses ) {
	if ( empty( $order_statuses ) ) {
		return;
	}

	$existing     = $this->get_saved_statuses_for_type( $order_type );
	$new_statuses = array_diff( $order_statuses, $existing );
	if ( empty( $new_statuses ) ) {
		return;
	}
	$merged = array_unique( array_merge( $existing, $new_statuses ) );

	wp_cache_set( $this->get_saved_statuses_cache_key( $order_type ), $merged, '', $this->expiration );
}