From 8b0915c4e090082d348cdd5985a0db0cb78146e8 Mon Sep 17 00:00:00 2001 From: roykho Date: Thu, 28 Jan 2021 08:26:24 -0800 Subject: [PATCH] Flush term cache when saving product and settings closes #25375 --- includes/admin/settings/class-wc-settings-products.php | 4 ++++ includes/data-stores/class-wc-product-data-store-cpt.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/includes/admin/settings/class-wc-settings-products.php b/includes/admin/settings/class-wc-settings-products.php index 8346e63c3ec..d48c5aa56f5 100644 --- a/includes/admin/settings/class-wc-settings-products.php +++ b/includes/admin/settings/class-wc-settings-products.php @@ -64,6 +64,10 @@ class WC_Settings_Products extends WC_Settings_Page { $settings = $this->get_settings( $current_section ); WC_Admin_Settings::save_fields( $settings ); + // Any time we update the product settings, we should flush the term count cache. + $tools_controller = new WC_REST_System_Status_Tools_Controller(); + $tools_controller->execute_tool( 'recount_terms' ); + if ( $current_section ) { do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section ); } diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index ed626f9a9b3..c705beef402 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -272,6 +272,9 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da $product->apply_changes(); + // Any time we update the product, we should flush the term count cache. + $tools_controller = new WC_REST_System_Status_Tools_Controller(); + $tools_controller->execute_tool( 'recount_terms' ); do_action( 'woocommerce_update_product', $product->get_id(), $product ); }