WC_Product_Data_Store_CPT::clear_caches
Clear any caches.
Метод класса: WC_Product_Data_Store_CPT{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->clear_caches( $product );
- $product(WC_Product) (обязательный) (передается по ссылке — &)
- Product object.
Список изменений
| С версии 3.0.0 | Введена. |
Код WC_Product_Data_Store_CPT::clear_caches() WC Product Data Store CPT::clear caches WC 11.1.2
protected function clear_caches( &$product ) {
wc_delete_product_transients( $product->get_id() );
if ( $product->get_parent_id( 'edit' ) ) {
wc_delete_product_transients( $product->get_parent_id( 'edit' ) );
WC_Cache_Helper::invalidate_cache_group( 'product_' . $product->get_parent_id( 'edit' ) );
}
WC_Cache_Helper::invalidate_attribute_count( array_keys( $product->get_attributes() ) );
WC_Cache_Helper::invalidate_cache_group( 'product_' . $product->get_id() );
// Clear product object cache last, as operations above may call wc_get_product() and re-cache.
if ( \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'product_instance_caching' ) ) {
$product_cache = wc_get_container()->get( ProductCache::class );
$product_cache->remove( $product->get_id() );
// Also clear parent's cache if this is a variation, as operations above may have cached
// the parent with stale children data.
$parent_id = $product->get_parent_id( 'edit' );
if ( $parent_id ) {
$product_cache->remove( $parent_id );
}
}
}