WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] update Count after hiding products (2 posts)

  1. nonobobo
    Member
    Posted 1 year ago #

    Hi,

    I've got total of 44 products. But 3 of them have been hide (no more stock). But they still are counted in the categories(44)
    I would prefer the count return the real number of products available. An idéa, i don't find any answer.

    Thanks
    Nora

    http://wordpress.org/extend/plugins/woocommerce/

  2. nonobobo
    Member
    Posted 1 year ago #

    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;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic