protected function update_term_counts(&$product)
{
if (!wp_defer_term_counting()) {
global $wc_allow_term_recount;
$wc_allow_term_recount = true;
$post_type = $product->is_type('variation') ? 'product_variation' : 'product';
// Update counts for the post's terms.
foreach ((array) get_object_taxonomies($post_type) as $taxonomy) {
$tt_ids = wc_get_object_terms($product->get_id(), $taxonomy, 'term_taxonomy_id');
wp_update_term_count($tt_ids, $taxonomy);
}
}
}