Zonic Design Knowledge Base

How to Set the Number of Products Per Page in WooCommerce

If your WordPress theme supports WooCommerce, then you might already have a setting that lets you set the number of products per page in your WooCommerce shop.

So, before jumping to the solution part, check your theme’s options for something like this:

This is how it looks on the Avada theme (affiliate link).

You can usually find your theme’s settings in Appearance > Theme Options or in Appearance > Customize if the developers integrated them there.

In case your WordPress theme doesn’t support WooCommerce, then I’ll show how to add a simple code that gets the job done.

Yes, if it’s possible and easy, we’ll be using a code, not a plugin 😀 . The fewer plugins you have, the better!

Change the number of products per page in WooCommerce

Before beginning, I recommend backing up the functions.php file or the entire website, as well as having a child theme in place, otherwise, the changes you make will disappear with the next theme update!

If you don’t have a child theme and it would be too complicated for you to set up one now, then you should use the Code Snippets plugin and add the code there.

Now, let’s get to it!

Step 1 – Access the functions.php file

Access your WordPress website’s files and edit the child theme’s functions.php file.

Editing functions.php via cPanel

It should normally be in /public_html/wp-content/themes/YourThemeName-child/functions.php.

If you’re using an add-on domain, not your main one, then it should be in /public_html/YourDomain/wp-content/themes/YourThemeName-child/functions.php.

Step 2 – Add the filter

Add the following PHP code (provided by the Woo devs) at the very bottom of the file or right before the ?> closing tag (if it exists).

/**
 * Change number of products that are displayed per page (shop page)
 */
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );

function new_loop_shop_per_page( $cols ) {
  $cols = 9;
  return $cols;
}

Don’t forget to update/save the file!

This filter will display 9 products per page.

To modify that number, simply change the value in $cols = 9;.

For example, if you want to display 12 products per page, then add 12 instead of 9: $cols = 12;.

That’s a wrap

I hope you found the post useful and managed to change the number of products displayed per page in your WooCommerce shop!

Don’t forget to share the post to help out others!

You can quickly subscribe to my newsletter by using this link.

If you have any questions or thoughts, drop a comment or send a message via contact or Facebook page.

You can also hit the follow button on Twitter and subscribe to the YouTube channel.

My WordPress installation service is at your disposal!

On-going WordPress support and maintenance services are on the menu as well!

Article from: ThemeSkills Posted by: ThemeSkills