Automattic\WooCommerce\Internal\Caches

ProductCacheController::invalidate_product_cachepublicWC 10.5.0

Invalidate the product cache for a given post ID if it's a product or product variation.

Method of the class: ProductCacheController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ProductCacheController = new ProductCacheController();
$ProductCacheController->invalidate_product_cache( $post_id ): void;
$post_id(int) (required)
The post ID to check and invalidate.

Changelog

Since 10.5.0 Introduced.

ProductCacheController::invalidate_product_cache() code WC 10.7.0

public function invalidate_product_cache( $post_id ): void {
	$post_id   = (int) $post_id;
	$post_type = get_post_type( $post_id );
	if ( ! $post_type || ! in_array( $post_type, array( 'product', 'product_variation' ), true ) ) {
		return;
	}

	$this->product_cache->remove( $post_id );
}