Skip to content

Instantly share code, notes, and snippets.

Last active November 21, 2023 11:32
Show Gist options
  • Save jameskoster/1601682 to your computer and use it in GitHub Desktop.
Save jameskoster/1601682 to your computer and use it in GitHub Desktop.
WooCommerce - change number of products displayed per page
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
Copy link

i want my products to be displayed as per this website ,
I have made changes in my theme's archive-product page, but not able to get as code for the archive page is

ID, "product_cat");?>
        <div class="page-content">      

            <?php if ( have_posts() ) : ?>

            <div class="product-image">

                <?php woocommerce_product_loop_start(); ?>

                <?php woocommerce_product_subcategories(); ?>

                <?php while ( have_posts() ) : the_post(); ?>

                <?php wc_get_template_part( 'content', 'product' ); ?>

                <?php endwhile; // end of the loop. ?>

                <?php woocommerce_product_loop_end(); ?>


                     * woocommerce_after_shop_loop hook
                     * @hooked woocommerce_pagination - 10
                    do_action( 'woocommerce_after_shop_loop' );


                    <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>

                    <?php wc_get_template( 'loop/no-products-found.php' ); ?>

                    <?php endif; ?>

Copy link

esucces commented Sep 7, 2015

I have set my shop page to show 12 products, works like a charm. But my search result page show only 10 products - is there a simular snippet I can use for the search result page?

Copy link

jnz31 commented Sep 23, 2015

this is a dynamic variant, if you want to have multiple values / let the user decide, how many articles should be shown. all you need is a variable called "show" in your url ( f.ex. will display 99 ).
if there is no variable, it will default to 9. or change the 9 at the end of the return statement..

add_filter( 'loop_shop_per_page', function ( $cols ) { return isset( $_GET['show'] ) ? wc_clean( $_GET['show'] ) : 9; }, 20 );

now all you need to do is add some buttons that set the variable "show" to your theme..

Copy link

s2ar commented Oct 3, 2015


Copy link

I registered my account to say thank you, thank you very much for saving my time its works perfectly.

Just added in this page

Copy link

A lot of my time is saved and boggling my mind i was screwed up but its so easy.. its in settings > Reading Settings > just change the page show at most to 12 where it was 10 by default..

special thanks to Boblebad

Copy link

Hi guys
Here it is completed for products and for rows:
Best Regards.
// Number of products to show per page ex 12

add_filter( 'loop_shop_per_page', function ( $cols ) {
return 12;
}, 20 );
// Number or products per row ex 4
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 4; // 5 products per row

Copy link

Will this change stick after a WooCommerce update?

Copy link

Aravin commented Jun 10, 2016

Not working for me. I can see the dropdown with options.

After choosing the option, there is no action.


Copy link

zoldos commented Oct 16, 2016

Worked great!

Copy link

Thanks a lot ! that works like cream 👍

Copy link

Works beautifully. Thank you!

Copy link

ghost commented Jan 11, 2017

Thanks :)!

Copy link

ghost commented Mar 21, 2017

@jameskoster Great It's working for me :)

Copy link

Not sure if I'm doing something wrong, but it's not working for me :/

I'm using a child theme for the Divi theme ( and added the code to my functions.php, but my store still shows just 9 products per page. If anyone has any idea what I might be doing wrong, I would appreciate it immensely. Thank you.

Copy link

@vivoeusebio there is an option in the divi settings

Copy link

paaljoachim commented Jul 11, 2017

I had a similar problem with a client site and have received some help from X theme support on the correct shortcode to use:

[product_category category="plakat-30x40cm" number="26" per_page="26"]

It worked well for the client site.

Copy link

put this code for my theme functions.php or new create wocommerce functions.php

Copy link

Josepek commented Aug 5, 2017

Oh! greats!

Copy link

This Plugin works fantastic, no need to change your coding, just install the plugin, change the amount of products you want and change the amount of rows also.

Copy link

HI, I'm having similar issue cannot get more than 5 products to be viewed for Categories but ONLY on mobile device. Works perfectly viewing 16 products per page on PC/Laptop and ipad.

Using Woocommerce, Storefront theme, Woocommerce products per page and other plugins.

Have also installed WOocommerce Products per page and works on PC/Laptop and Ipad.

But no matter what only 5 products MAX showing on each category for MOBILE ONLY.

Have been googling for days to resolve this issue, no-one seems to know or I haven't found the right support yet !
I see the functions.php snippet everywhere but that doesn't help for the mobile view.

Using WP Touch and just want to ADD in snippet of code to CHANGE the number of products viewed on mobile to 20 per page.
It's across all pages in WOocommerce for mobile.

I tried to find the settings in Theme Storefront and have submitted a ticket but no response to them.
Have submitted a ticket to WP Touch also still waiting.
And submitted on support forum also.

If it displays 2 columns on mobile could this be causing an issue ?
I prefer having 2 columns of products on the mobile ..
as I have the home page which displays 1 product per line and shows more than 5 .. this is the ONLy page that is normal more than 5.
So maybe a line of CSS code to allow it to KNOW more products to be shown more than 5 somehow.

Any help great appreciated.



Copy link

Go to yourdomainname/wp-admin/options-reading.php

@chameleonwebservices that's exactly what I was looking for, I knew it had to be somewhere in the Wordpress settings.

Thanks a lot buddy.

Copy link

Thanks Work for me.

Copy link

pablo-sg-pacheco commented Dec 7, 2018

If you want to make it work on DIVI theme you can try this approach.
It will override the DIVI settings.

add_filter( 'option_et_divi', function( $option ){
	$option['divi_woocommerce_archive_num_posts'] = 6;
	return $option;
} );

Copy link

If you want to make it work on DIVI theme you can try this approach.
It will override the DIVI settings.

add_filter( 'option_et_divi', function( $option ){
	$option['divi_woocommerce_archive_num_posts'] = 6;
	return $option;
} );

Thanks a lot!

Copy link

peterg23 commented Apr 9, 2019

@pablo-sg-pacheco thank you!

Copy link

@gabriel-munteanu HI there! I´m new in GITHUB. I will appreciate your help with the same issue of Products Per Page in Enfold Theme, for Woocommerce, I´ve tried the code above, I've tried Code Snippets, I've tried similar codes but nothing works for me. It only Return 12 products per Page as default. Thanks in advance.

Copy link

@PaolaGress Maybe you should look in the source code of your theme to check if there is a hard-coded value.
As far as I remember, the code snippet form above was meant to be put inside functions.php in a child theme of your main theme.
Hope this helps!

Copy link

add_action( 'woocommerce_product_query', 'woocommerce_product_query' );
function woocommerce_product_query( $q ) {
    if ( $q->is_main_query() && ( $q->get( 'wc_query' ) === 'product_query' ) ) {
        $q->set( 'posts_per_page', '5' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment