_wc_recount_terms_by_product()
Recounts terms by product.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null. Nothing (null).
Usage
_wc_recount_terms_by_product( $product_id );
- $product_id(int)
- The ID of the product.
Default:''
Changelog
| Since 5.2 | Introduced. |
_wc_recount_terms_by_product() wc recount terms by product code WC 10.6.2
function _wc_recount_terms_by_product( $product_id = '' ) {
if ( empty( $product_id ) ) {
return;
}
$product_terms = get_the_terms( $product_id, 'product_cat' );
if ( $product_terms ) {
$product_cats = array();
foreach ( $product_terms as $term ) {
$product_cats[ $term->term_id ] = $term->parent;
}
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), false, false );
}
$product_terms = get_the_terms( $product_id, 'product_tag' );
if ( $product_terms ) {
$product_tags = array();
foreach ( $product_terms as $term ) {
$product_tags[ $term->term_id ] = $term->parent;
}
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
}
}