wc_delete_product_transients( int $post_id )
Clear transient cache for product data.
Description Description
Parameters Parameters
- $post_id
-
(Required) (default: 0) The product ID.
Source Source
File: includes/wc-product-functions.php
function wc_delete_product_transients( $post_id = 0 ) {
// Transient data to clear with a fixed name which may be stale after product updates.
$transients_to_clear = array(
'wc_products_onsale',
'wc_featured_products',
'wc_outofstock_count',
'wc_low_stock_count',
);
foreach ( $transients_to_clear as $transient ) {
delete_transient( $transient );
}
if ( $post_id > 0 ) {
// Transient names that include an ID - since they are dynamic they cannot be cleaned in bulk without the ID.
$post_transient_names = array(
'wc_product_children_',
'wc_var_prices_',
'wc_related_',
'wc_child_has_weight_',
'wc_child_has_dimensions_',
);
foreach ( $post_transient_names as $transient ) {
delete_transient( $transient . $post_id );
}
}
// Increments the transient version to invalidate cache.
WC_Cache_Helper::get_transient_version( 'product', true );
do_action( 'woocommerce_delete_product_transients', $post_id );
}