WC_Post_Data::on_product_attributes_updated
Handles regeneration of variation summaries when a variable product's attributes are updated.
Method of the class: WC_Post_Data{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Post_Data::on_product_attributes_updated( $product );
- $product(WC_Product) (required)
- The variable product whose attributes were updated.
Changelog
| Since 10.2.0 | Introduced. |
WC_Post_Data::on_product_attributes_updated() WC Post Data::on product attributes updated code WC 10.5.0
public static function on_product_attributes_updated( $product ) {
if ( $product->is_type( 'variable' ) ) {
global $wpdb;
$threshold = self::get_variation_summaries_sync_threshold();
$variation_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT ID
FROM {$wpdb->posts}
WHERE post_parent = %d
AND post_type = %s
LIMIT %d
",
$product->get_id(),
'product_variation',
$threshold + 1
)
);
if ( empty( $variation_ids ) ) {
return;
}
if ( count( $variation_ids ) <= $threshold ) {
// If the number of variations is below the threshold, regenerate summaries synchronously.
$variation_ids = $product->get_children();
self::regenerate_variation_summaries( $variation_ids );
} else {
self::schedule_variation_summary_regeneration(
'wc_regenerate_product_variation_summaries',
array( $product->get_id() ),
'Product ID: ' . $product->get_id()
);
}
}
}