wc_recount_all_terms()
Recounts all terms for product categories, tags, and brands.
No Hooks.
Returns
void. Nothing (null).
Usage
wc_recount_all_terms( $include_callback );
- $include_callback(true|false)
- True to update the standard term counts in addition to the product-specific counts, which will cause a lot more queries to run.
Default:true
Changelog
| Since 5.2 | Introduced. |
wc_recount_all_terms() wc recount all terms code WC 11.1.2
function wc_recount_all_terms( bool $include_callback = true ) {
$product_cats = get_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'fields' => 'id=>parent',
)
);
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), $include_callback, false );
$product_tags = get_terms(
array(
'taxonomy' => 'product_tag',
'hide_empty' => false,
'fields' => 'id=>parent',
)
);
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), $include_callback, false );
$product_brands = get_terms(
array(
'taxonomy' => 'product_brand',
'hide_empty' => false,
'fields' => 'id=>parent',
)
);
$product_brand_taxonomy = get_taxonomy( 'product_brand' );
if ( is_array( $product_brands ) && $product_brand_taxonomy instanceof WP_Taxonomy ) {
_wc_term_recount( $product_brands, $product_brand_taxonomy, $include_callback, false );
}
}