Restore code to delete wc_layered_nav_counts_* transients

Commit a9994feeea removed the code to delete wc_layered_nav_counts_* transients whenever a product attribute is updated and moved it to wc_delete_product_transients(). This was done to make sure those transients are deleted whenever a product is updated and not only when a product attribute changes. But, as Claudiu pointed out (https://github.com/woocommerce/woocommerce/pull/22029#issuecomment-451473512), this change introduced a bug as if you remove an attribute from a product, by the time the code reaches wc_delete_product_transients() the changes have been applied already to the product, the attribute doesn't belong to it anymore, and thus the layered nav counts transient for that attribute is not deleted.

To work around this problem, this commit restores the code that deletes wc_layered_nav_counts_* transients inside WC_Product_Data_Store_CPT::update_attributes(). Now, in most cases, WC will try to delete the same transient twice, but I can't see any other way to implement a solution for the problem above without doing this.
This commit is contained in:
Rodrigo Primo 2019-01-10 14:19:03 -02:00
parent a9994feeea
commit c82346b095
1 changed files with 2 additions and 0 deletions

View File

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