Number of products in shop page

in my site at shop page

the products are shown on 3 columns, but are shown 10 products and the last row has 2 empty spaces

can we set an odd number of products to show (9 or 6)



I suggest you to create a child theme and add this line of code to its functions.php as described here:

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 9;' ), 20 );

Sincerely, Roman.

Here is the line of code (it’s cut in message above):

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 24;’ ), 20 );

Just replace “return 24” to the number of your choice, 6 or 9.

So you will get, for example:

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );

why create a child theme?
is not possible add that line in the main theme?


It is possible to add it to the main theme, but you will have to re-add it after updating the main theme.


Where exactely in the functions.php do I have add the line?

I tryed to add it at the hand but I recive an error

thanks again

PHP code always has to be within its tags, <?php some code ?>. Opening tag “<?php” is necessary, closing tag “?>” is not necessary, so it is recommended to avoid closing tag at all in files that contain only PHP code (you still must use both tags to separate PHP from HTML). So, recommended function.php structure in terms of tags is:

some code

I bag your pardon but I can’t understand
…in the file php at the top I have

 * TheShop functions and definitions
 * @package TheShop

if ( ! function_exists( 'theshop_setup' ) ) :
 * Sets up theme defaults and registers support for various WordPress features.
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
function theshop_setup() {


and in the end

  • Woocommerce
    require get_template_directory() . ‘/woocommerce/woocommerce.php’;

Okay, just put this code at the end of the file:

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );

So I did but I have this error:

Parse error: syntax error, unexpected ‘$cols’’ (T_VARIABLE) in /web/htdocs/ on line 272


Please check the code carefully, it has to be ‘$cols’, not ‘$cols’’.

…I cheked, in the php file is correct


  • Woocommerce
    require get_template_directory() . ‘/woocommerce/woocommerce.php’;

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );

…I’m working on the functions.phf file tha is located in:

is it the correct file location?

You can also try WooCommerce Products Per Page plugin.


the error was in the '
so instead of paste and place I edited the line manually

thanks a lot

I’m glad that you figured it out! :slight_smile:

Hey, I don’t know if this’ll wwork for you but if you are in the dashboard, go to settings-reading-show amount of blogposts --insert number you need that might just fix your product numbers…illogical I know but I think you will have success.

Hello @mj,

Thank you for your suggestion. I, personally, think that this is good idea. We will discuss this issue.

Kind Regards, Roman.