Delete wc_layered_nav_counts_* transients whenever a product is updated

This commit moves the code to delete wc_layered_nav_counts_* transients from WC_Product_Data_Store_CPT::update_attributes() to wc_delete_product_transients(). This way those transients will be deleted whenever a product is updated and not only when the product attributes are updated. This is needed to make sure that the "Filter Products by Attribute" displays the correct list of attributes when a product changes from out of stock to in stock or vice versa via the "Quick Edit" interface or the WC API.
This commit is contained in:
Rodrigo Primo 2018-11-23 15:30:38 -02:00
parent 8d5b428a29
commit a9994feeea
2 changed files with 8 additions and 2 deletions

View File

@ -738,8 +738,6 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
foreach ( $attributes as $attribute_key => $attribute ) { foreach ( $attributes as $attribute_key => $attribute ) {
$value = ''; $value = '';
delete_transient( 'wc_layered_nav_counts_' . $attribute_key );
if ( is_null( $attribute ) ) { if ( is_null( $attribute ) ) {
if ( taxonomy_exists( $attribute_key ) ) { if ( taxonomy_exists( $attribute_key ) ) {
// Handle attributes that have been unset. // Handle attributes that have been unset.

View File

@ -134,6 +134,14 @@ function wc_delete_product_transients( $post_id = 0 ) {
'products' 'products'
); );
} }
$attributes = $product->get_attributes();
if ( $attributes ) {
foreach ( $attributes as $attribute_key => $attribute ) {
$transients_to_clear[] = 'wc_layered_nav_counts_' . $attribute_key;
}
}
} }
} }