wc_change_term_counts( array $terms, string|array $taxonomies )
Overrides the original term count for product categories and tags with the product count.
Description Description
that takes catalog visibility into account.
Parameters Parameters
- $terms
-
(Required) List of terms.
- $taxonomies
-
(Required) Single taxonomy or list of taxonomies.
Return Return
(array)
Source Source
File: includes/wc-term-functions.php
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | function wc_change_term_counts( $terms , $taxonomies ) { if ( is_admin() || is_ajax() ) { return $terms ; } if ( ! isset( $taxonomies [0] ) || ! in_array( $taxonomies [0], apply_filters( 'woocommerce_change_term_counts' , array ( 'product_cat' , 'product_tag' ) ), true ) ) { return $terms ; } $o_term_counts = get_transient( 'wc_term_counts' ); $term_counts = $o_term_counts ; foreach ( $terms as & $term ) { if ( is_object ( $term ) ) { $term_counts [ $term ->term_id ] = isset( $term_counts [ $term ->term_id ] ) ? $term_counts [ $term ->term_id ] : get_term_meta( $term ->term_id, 'product_count_' . $taxonomies [0], true ); if ( '' !== $term_counts [ $term ->term_id ] ) { $term -> count = absint( $term_counts [ $term ->term_id ] ); } } } // Update transient. if ( $term_counts !== $o_term_counts ) { set_transient( 'wc_term_counts' , $term_counts , DAY_IN_SECONDS * 30 ); } return $terms ; } |