WC_Post_Data::handle_attribute_term_updated
Hook called after a term is updated to handle updates for product variations.
Method of the class: WC_Post_Data{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Post_Data::handle_attribute_term_updated( $term_id, $tt_id, $taxonomy );
- $term_id(int) (required)
- Term ID.
- $tt_id(int) (required)
- Term taxonomy ID.
- $taxonomy(string) (required)
- Taxonomy slug.
WC_Post_Data::handle_attribute_term_updated() WC Post Data::handle attribute term updated code WC 10.8.1
public static function handle_attribute_term_updated( $term_id, $tt_id, $taxonomy ) {
if ( strpos( $taxonomy, 'pa_' ) !== 0 ) {
return;
}
$new_term = get_term( $term_id, $taxonomy );
if ( is_wp_error( $new_term ) || ! $new_term ) {
return;
}
$meta_key = 'attribute_' . $taxonomy;
global $wpdb;
$threshold = self::get_variation_summaries_sync_threshold();
$variation_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT pm.post_id
FROM $wpdb->postmeta pm
INNER JOIN $wpdb->posts p ON pm.post_id = p.ID
WHERE pm.meta_key = %s
AND pm.meta_value = %s
AND p.post_type = 'product_variation'
LIMIT %d
",
$meta_key,
$new_term->slug,
$threshold + 1
)
);
if ( empty( $variation_ids ) ) {
return;
}
if ( count( $variation_ids ) <= $threshold ) {
// If the number of variations is below the threshold, regenerate summaries synchronously.
self::regenerate_variation_summaries( $variation_ids );
} else {
self::schedule_variation_summary_regeneration(
'wc_regenerate_term_variation_summaries',
array( $taxonomy, $new_term->slug ),
'Taxonomy: ' . $taxonomy . ', Term ID: ' . $term_id
);
}
}