Quantcast
Channel: WordPress.org Forums » [WooCommerce] Support
Viewing all articles
Browse latest Browse all 104029

nonobobo on "[Plugin: WooCommerce - excelling eCommerce] update Count after hiding products"

$
0
0

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 all articles
Browse latest Browse all 104029

Trending Articles