From 9389cf40894dbde9a8937f3d93662d25bb75eefb Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 29 Nov 2018 17:33:16 +0100 Subject: [PATCH] Added storing attribute values as post_excerpt for variations. This allows searching for variations by their attributes without cluttering the Variation's title. --- .../data-stores/class-wc-product-variation-data-store-cpt.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 b209f4b485c..86a4aabc24b 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 @@ -118,6 +118,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl 'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_author' => get_current_user_id(), 'post_title' => $product->get_name( 'edit' ), + 'post_excerpt' => wc_get_formatted_variation( $product, true, false ), 'post_content' => '', 'post_parent' => $product->get_parent_id(), 'comment_status' => 'closed', @@ -177,9 +178,10 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl $changes = $product->get_changes(); // Only update the post when the post data changes. - if ( array_intersect( array( 'name', 'parent_id', 'status', 'menu_order', 'date_created', 'date_modified' ), array_keys( $changes ) ) ) { + if ( array_intersect( array( 'name', 'parent_id', 'status', 'menu_order', 'date_created', 'date_modified', 'attributes' ), array_keys( $changes ) ) ) { $post_data = array( 'post_title' => $product->get_name( 'edit' ), + 'post_excerpt' => wc_get_formatted_variation( $product, true, false ), 'post_parent' => $product->get_parent_id( 'edit' ), 'comment_status' => 'closed', 'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',