Automattic\WooCommerce\Caches
ProductCountCache::flush
Flush the cache for a given product type and statuses.
Method of the class: ProductCountCache{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ProductCountCache = new ProductCountCache(); $ProductCountCache->flush( $product_type, $product_statuses ): void;
- $product_type(string)
- The post type (e.g.
'product', 'product_variation').
Default:'product' - $product_statuses(string[])
- The statuses to flush. Flushes all known statuses if empty.
Default:array()
ProductCountCache::flush() ProductCountCache::flush code WC 11.0.0
public function flush( string $product_type = 'product', array $product_statuses = array() ): void {
$flush_saved_statuses = false;
if ( empty( $product_statuses ) ) {
$product_statuses = $this->get_saved_statuses_for_type( $product_type );
$flush_saved_statuses = true;
}
$cache_keys = array_map(
fn ( $product_status ) => $this->get_cache_key( $product_type, $product_status ),
$product_statuses
);
if ( $flush_saved_statuses ) {
// If all statuses are being flushed, go ahead and flush the status list so any permanently removed statuses are cleared out.
$cache_keys[] = $this->get_saved_statuses_cache_key( $product_type );
}
wp_cache_delete_multiple( $cache_keys );
}