From 2ed018d5420f92903b8e28e93e7a4526e6254b96 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 3 Apr 2018 12:51:58 +0100 Subject: [PATCH] Trigger post modified update when saving products and variations, but no other product data Closes #19562 --- .../data-stores/class-wc-product-data-store-cpt.php | 13 +++++++++++++ .../class-wc-product-variation-data-store-cpt.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) 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 5f94ae8af41..14bc1e530b0 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -221,6 +221,19 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da wp_update_post( array_merge( array( 'ID' => $product->get_id() ), $post_data ) ); } $product->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. + + } else { // Only update post modified time to record this save event. + $GLOBALS['wpdb']->update( + $GLOBALS['wpdb']->posts, + array( + 'post_modified' => current_time( 'mysql' ), + 'post_modified_gmt' => current_time( 'mysql', 1 ), + ), + array( + 'ID' => $product->get_id(), + ) + ); + clean_post_cache( $product->get_id() ); } $this->update_post_meta( $product ); diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index b5ad1b673be..e98d178711e 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -207,6 +207,19 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl wp_update_post( array_merge( array( 'ID' => $product->get_id() ), $post_data ) ); } $product->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. + + } else { // Only update post modified time to record this save event. + $GLOBALS['wpdb']->update( + $GLOBALS['wpdb']->posts, + array( + 'post_modified' => current_time( 'mysql' ), + 'post_modified_gmt' => current_time( 'mysql', 1 ), + ), + array( + 'ID' => $product->get_id(), + ) + ); + clean_post_cache( $product->get_id() ); } $this->update_post_meta( $product );