Automattic\WooCommerce\Caches

OrderCountCache::getpublicWC 1.0

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

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

Хуков нет.

Возвращает

Массив<Строку,int>|null. The cache value.

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

$OrderCountCache = new OrderCountCache();
$OrderCountCache->get( $order_type, $order_statuses );
$order_type(строка) (обязательный)
The type of order.
$order_statuses(string[])
The statuses to retrieve.
По умолчанию: array()

Код OrderCountCache::get() 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;
}