Home / Archive / Show Products Count on WooCommerce Archive Pages
Duplicate Snippet

Embed Snippet on Your Site

Show Products Count on WooCommerce Archive Pages

Display number of products listed using the [product_count] shortcode

<10
Code Preview
php
<?php
add_shortcode( 'product_count', 'product_count_shortcode' );
function product_count_shortcode() {
	global $wp_query;
	$total_product_count = $wp_query->found_posts;
	$current_page = max( 1, get_query_var( 'paged' ) );
	$products_per_page = get_option( 'posts_per_page' );
	$start_product = ( ( $current_page - 1 ) * $products_per_page ) + 1;
	$end_product = min( $start_product + $products_per_page - 1, $total_product_count );
	$message = sprintf( 'Showing <span class="count-from-to">%d-%d</span> of <span class="count-total">%d</span> products', $start_product, $end_product, $total_product_count );
	return '<div class="cwf-products-count">' . $message . '</div>';
}

Comments

Add a Comment