Woocoomerce product category count including subcategories

WP_Query can be used to determine the number of posts contained within a category and its subcategories.

In the code below, set the terms parameter to whatever the parent category ID is. The include_children parameter ensures that WP_Query will include posts within subcategories.

We can then use $query->post_count to get the total number of posts in the parent category and its subcategories.

$query = new WP_Query( array(
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'id',
            'terms' => 79, // Replace with the parent category ID
            'include_children' => true,
        ),
    ),
    'nopaging' => true,
    'fields' => 'ids',
) );

echo '<p>Total product count: <strong>' . esc_html( $query->post_count ) . '</strong></p>';