WC_Post_Data::regenerate_variation_attribute_summary
Regenerates the attribute summary for a single variation.
Method of the class: WC_Post_Data{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Post_Data::regenerate_variation_attribute_summary( $variation_id );
- $variation_id(int) (required)
- Variation ID.
Changelog
| Since 10.2.0 | Introduced. |
WC_Post_Data::regenerate_variation_attribute_summary() WC Post Data::regenerate variation attribute summary code WC 10.5.0
public static function regenerate_variation_attribute_summary( $variation_id ) {
global $wpdb;
$product = wc_get_product( $variation_id );
if ( ! $product || ! $product->is_type( 'variation' ) ) {
return;
}
$data_store = WC_Data_Store::load( 'product-variation' );
if ( $data_store->has_callable( 'get_attribute_summary' ) ) {
$new_summary = $data_store->get_attribute_summary( $product );
$current_excerpt = get_post_field( 'post_excerpt', $variation_id );
if ( $new_summary === $current_excerpt ) {
return;
}
/**
* Update directly via $wpdb for performance: Avoid firing save_post hooks, loading full post objects,
* and creating revisions. This is safe here as we're only updating post_excerpt.
*/
$wpdb->update(
$wpdb->posts,
array( 'post_excerpt' => $new_summary ),
array( 'ID' => $variation_id )
);
clean_post_cache( $variation_id );
/**
* Fires after the attribute summary of a product variation has been updated.
*
* @since 10.2.0
* @param int $variation_id The ID of the product variation.
*/
do_action( 'woocommerce_updated_product_attribute_summary', $variation_id );
}
}