Automattic\WooCommerce\Caches
ProductCountCacheService::update_on_product_deleted
Update the cache when a product is permanently deleted.
Method of the class: ProductCountCacheService{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ProductCountCacheService = new ProductCountCacheService(); $ProductCountCacheService->update_on_product_deleted( $post_id, $post ): void;
- $post_id(int) (required)
- Post ID.
- $post(WP_Post) (required)
- The post object.
ProductCountCacheService::update_on_product_deleted() ProductCountCacheService::update on product deleted code WC 11.0.0
public function update_on_product_deleted( int $post_id, WP_Post $post ): void {
if ( 'product' === $post->post_type ) {
// Reverse any errant decrement from a mid-creation status transition that update_on_new_product will never get to correct.
$this->maybe_restore_initial_status_count( $post_id );
$product_status = $post->post_status;
if ( $this->product_count_cache->is_cached( 'product', $product_status ) ) {
$this->product_count_cache->decrement( 'product', $product_status );
}
unset( $this->product_statuses[ $post_id ], $this->products_in_creation[ $post_id ] );
}
}