Added lazy-update of post_excerpt for variations to avoid the need for db update routine.
This commit is contained in:
parent
6f9ec2c7de
commit
06118db3d5
|
@ -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 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue