xxxxxxxxxx
// PRODUCT COUNTS FUNCTION
function display_category_counts_on_homepage( $category ) {
$terms = get_terms( 'product_cat' );
// DEBUG
// var_dump( $terms );
foreach( $terms as $term )
{
if($term->name == 'NEW'){
echo $term->count;
}
}
}
add_action( 'woocommerce_single_product_summary', 'display_category_counts_on_homepage' );
xxxxxxxxxx
add_action('woocommerce_before_main_content','category_product_count');
function category_product_count(){
$category_id = get_queried_object_id(); // Get the ID of the current category page
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args );
foreach($all_categories as $category){
if($category->cat_ID == $category_id)
echo '<h1>Showing total result:'.$category->count.' </h1>';
}
}