From 06118db3d50ed88ed33200066adaf7e954647dcf Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Tue, 26 Feb 2019 11:11:45 +0100 Subject: [PATCH] Added lazy-update of post_excerpt for variations to avoid the need for db update routine. --- .../class-wc-product-variation-data-store-cpt.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 e376fe47b10..974cb7eeb5b 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 @@ -61,6 +61,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl 'menu_order' => $post_object->menu_order, 'reviews_allowed' => 'open' === $post_object->comment_status, 'parent_id' => $post_object->post_parent, + 'post_excerpt' => $post_object->post_excerpt, ) ); @@ -85,6 +86,20 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl clean_post_cache( $product->get_id() ); } + /** + * If a variation has no excerpt, update here. Used when searching for variations by attribute names. + */ + if ( '' === $post_object->post_excerpt ) { + $new_excerpt = wc_get_formatted_variation( $product, true, false ); + $product->set_props( + array( + 'post_excerpt' => $new_excerpt, + ) + ); + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_excerpt' => $new_excerpt ), array( 'ID' => $product->get_id() ) ); + clean_post_cache( $product->get_id() ); + } + // Set object_read true once all data is read. $product->set_object_read( true ); }