WC_Post_Data::handle_attribute_term_deletedpublic staticWC 1.0

Hook called after a term is deleted 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_deleted( $term_id, $tt_id, $taxonomy, $deleted_term );
$term_id(int) (required)
Term ID.
$tt_id(int) (required)
Term taxonomy ID.
$taxonomy(string) (required)
Taxonomy slug.
$deleted_term(WP_Term) (required)
Copy of the already-deleted term.

WC_Post_Data::handle_attribute_term_deleted() code WC 10.7.0

public static function handle_attribute_term_deleted( $term_id, $tt_id, $taxonomy, $deleted_term ) {
	if ( strpos( $taxonomy, 'pa_' ) !== 0 ) {
		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,
			$deleted_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, $deleted_term->slug ),
			'Taxonomy: ' . $taxonomy . ', Term ID: ' . $term_id
		);
	}
}