Category name with total number of product in that category in woocomerce

can anyone explain me how to show the category title with the number of product in that category in category archive page like category 1(10)

the url is http://www.example.com/product-category/category-1/

Read More

Can anyone help me…………..
I have tried this but it display total product of the website. I want only the product in that category

<h1><?php woocommerce_page_title(); 


global $woocommerce_loop;
 do_action( 'woocommerce_before_subcategory', $category ); 

                    echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . $category->count . ')</mark>', $category );
        ?>  


        </h1>

Related posts

Leave a Reply

2 comments

  1. I am able to solve this

    <h1><?php woocommerce_page_title(); 
    
    
    
    global $wp_query;
    // get the query object
    $cat_obj = $wp_query->get_queried_object();
    
    
    if($cat_obj)    {
        $category_name = $cat_obj->name;
        $category_desc = $cat_obj->description;
        $category_ID  = $cat_obj->term_id;
    }
    
    
    $term = get_term( $category_ID, 'product_cat' ); 
    echo '('. $term->count . ')';
    
    
    ?>      
            </h1>
    

    Placed this in “archive-product.php”

  2. To list all the categories along with the product count:

    $terms = get_terms( 'product_cat' ); 
    foreach( $terms as $term ) 
    {
        echo 'Product Category: '
            . $term->name
            . ' - Count: '
            . $term->count;
    } 
    

    If you have a category ID:

    $term = get_term( CAT_ID, 'product_cat' );   //Replace your category ID here
    echo 'Product Category: '
        . $term->name
        . ' - Count: '
        . $term->count;