Added lazy-update of post_excerpt for variations to avoid the need for db update routine.

This commit is contained in:
Peter Fabian 2019-02-26 11:11:45 +01:00
parent 6f9ec2c7de
commit 06118db3d5
1 changed files with 15 additions and 0 deletions

View File

@ -61,6 +61,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
'menu_order' => $post_object->menu_order, 'menu_order' => $post_object->menu_order,
'reviews_allowed' => 'open' === $post_object->comment_status, 'reviews_allowed' => 'open' === $post_object->comment_status,
'parent_id' => $post_object->post_parent, '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() ); 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. // Set object_read true once all data is read.
$product->set_object_read( true ); $product->set_object_read( true );
} }