WooCommerce number of archive products per page

This code snippet allows you to set a specific number of products to display per page on your WooCommerce shop or archive pages.

The function my_new_products_per_page changes the number of products displayed per page on the WooCommerce shop or archive pages. The function is called by the filter loop_shop_per_page provided by WooCommerce. The number of products per page is set to 16 in this example, but you can change the value of $pr_per_page to any integer that fits your needs.

This is particularly useful when you want to control the number of products your visitors see on a single page, which can impact their browsing experience and your website’s performance. By default, WooCommerce uses the number set in the WordPress Reading settings for blog posts per page. With this code, you can set a different number for your WooCommerce products without affecting the blog posts per page setting.

PHP
/*  Change WooCommerce Archive products number per page */
 
add_filter( 'loop_shop_per_page', 'my_new_products_per_page', 9999 );
 
function my_new_products_per_page( $pr_per_page ) {
  $pr_per_page = 16;
  return $pr_per_page;
}