Automattic\WooCommerce\Caches

OrderCountCache::getpublicWC 1.0

Get the cache value for a given order type and set of statuses.

Method of the class: OrderCountCache{}

No Hooks.

Returns

array<string,int>|null. The cache value.

Usage

$OrderCountCache = new OrderCountCache();
$OrderCountCache->get( $order_type, $order_statuses );
$order_type(string) (required)
The type of order.
$order_statuses(string[])
The statuses to retrieve.
Default: array()

OrderCountCache::get() code WC 11.0.1

public function get( $order_type, $order_statuses = array() ) {
	$order_type = (string) $order_type;
	if ( empty( $order_statuses ) ) {
		$order_statuses = $this->get_saved_statuses_for_type( $order_type );
		if ( empty( $order_statuses ) ) {
			return null;
		}
	}

	$cache_keys = array_map(
		fn( $order_statuses ) => $this->get_cache_key( $order_type, $order_statuses ),
		$order_statuses
	);

	$cache_values  = wp_cache_get_multiple( $cache_keys );
	$status_values = array();

	$cache_key_prefix = $this->get_cache_key( $order_type, '' );
	foreach ( $cache_values as $key => $value ) {
		// Return null for the entire cache if any of the requested statuses are not found because they fell out of cache.
		if ( false === $value ) {
			return null;
		}

		$status                   = substr( $key, strlen( $cache_key_prefix ) );
		$status_values[ $status ] = $value;
	}

	return $status_values;
}