Automattic\WooCommerce\Caches

ProductCountCache::set_multiplepublicWC 1.0

Set the cache count value for multiple statuses at once.

Method of the class: ProductCountCache{}

No Hooks.

Returns

Array.

Usage

$ProductCountCache = new ProductCountCache();
$ProductCountCache->set_multiple( $product_type, $counts );
$product_type(string) (required)
The post type (e.g. 'product', 'product_variation').
$counts(array<string,int>) (required)
Counts keyed by status slug (e.g. [ 'publish' => 10, 'draft' => 5 ]).

ProductCountCache::set_multiple() code WC 11.0.0

public function set_multiple( string $product_type, array $counts ) {
	if ( empty( $counts ) ) {
		return array();
	}

	$this->ensure_statuses_for_type( $product_type, array_keys( $counts ) );

	$mapped_counts = array();
	foreach ( $counts as $status => $count ) {
		$mapped_counts[ $this->get_cache_key( $product_type, $status ) ] = (int) $count;
	}

	return wp_cache_set_multiple( $mapped_counts, '', $this->expiration );
}