Automattic\WooCommerce\Caches
ProductCountCache::get
Get the cache value for a given product type and set of statuses.
Метод класса: ProductCountCache{}
Хуков нет.
Возвращает
Массив<Строку,int>|null.
Использование
$ProductCountCache = new ProductCountCache(); $ProductCountCache->get( $product_type, $product_statuses );
- $product_type(строка) (обязательный)
- The post type (e.g.
'product', 'product_variation'). - $product_statuses(string[])
- The statuses to retrieve.
По умолчанию:array()
Код ProductCountCache::get() ProductCountCache::get WC 11.0.1
public function get( string $product_type, array $product_statuses = array() ) {
if ( empty( $product_statuses ) ) {
$product_statuses = $this->get_saved_statuses_for_type( $product_type );
if ( empty( $product_statuses ) ) {
return null;
}
}
$cache_keys = array_map(
fn( $product_status ) => $this->get_cache_key( $product_type, $product_status ),
$product_statuses
);
$cache_values = wp_cache_get_multiple( $cache_keys );
$status_values = array();
$cache_key_prefix = $this->get_cache_key( $product_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;
}