WordPress.org

Support

Support » Plugins and Hacks » [Resolved] update Count after hiding products

[Resolved] update Count after hiding products

Viewing 1 replies (of 1 total)
  • I found the solution on a website, but don’t remember where …

    add this functions in woocommerce-core-functions.php :

    add_filter( ‘get_terms’, ‘wc_get_terms_filter’, 10, 2 );

    function wc_get_terms_filter( $terms, $taxonomies ) {
    if ( ! is_admin() && in_array( ‘product_cat’, $taxonomies ) ) {
    foreach ( $terms as $term ) {
    $query_args = array(
    ‘post_type’ => ‘product’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘id’,
    ‘terms’ => array( $term->term_id ),
    ),
    ),
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘_visibility’,
    ‘value’ => ‘hidden’,
    ),
    ),
    );

    $query = new WP_Query( $query_args );
    $term->count = $term->count – count( $query->posts );
    }
    }

    return $terms;
    }

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] update Count after hiding products’ is closed to new replies.