Order get_terms by count using a custom taxonomy hierarchy

Don’t know if it’s the best solution but I ended up using a custom query to show all categories ordered by count.

$cats = $wpdb->get_results("
    select tt.term_id, count, name, slug
    from ".$wpdb->prefix."term_taxonomy as tt
    inner join ".$wpdb->prefix."terms as terms
    on tt.term_id = terms.term_id
    where taxonomy = 'product_cat' 
    order by count desc limit 10
");
echo '<pre>'; print_r($cats); echo '</pre>';