Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
@jasonfredin

This comment has been minimized.

Copy link

jasonfredin commented Feb 24, 2012

Thanks, worked beautifully! Used to display 12 (instead of 24) items on a page instead of the usual 10 (leaving two empty)

@jeff01050

This comment has been minimized.

Copy link

jeff01050 commented Apr 3, 2012

were do I add this to? thanks again

EDIT* got it theme function.php

@danriti

This comment has been minimized.

Copy link

danriti commented Aug 11, 2012

fantastic!

@yoxalld

This comment has been minimized.

Copy link

yoxalld commented Aug 15, 2012

Is there a way to change this on the fly? I want to add a button to view all items on the main shop page. Thanks!

@ghost

This comment has been minimized.

Copy link

ghost commented Nov 9, 2012

Great! But it doesn't work if you add a new taxonomy to the product and you want to get more products.

@jorgeSr

This comment has been minimized.

Copy link

jorgeSr commented Dec 10, 2012

Great !

@jjbbrr

This comment has been minimized.

Copy link

jjbbrr commented Apr 3, 2013

Used exactly as presented here and it worked perfectly (using Wordpress 3.5.1 and Woocommerce 2.0.5)

@core2kx

This comment has been minimized.

Copy link

core2kx commented Apr 10, 2013

Fantastic solution! Thank you very much. WP 3.5.1 WC 2.0.5 Works perfectly.

@JohnnyBravoRad

This comment has been minimized.

Copy link

JohnnyBravoRad commented Apr 26, 2013

Юзаю тему Sommerce. Захожу в редактор,выбираем тему, потом functions.php
Добавляем в конце эту строчку и вуа ля:

@companyhen

This comment has been minimized.

Copy link

companyhen commented May 1, 2013

Thanks :)!

@sandalian

This comment has been minimized.

Copy link

sandalian commented Jul 13, 2013

Excellent!

@wteja

This comment has been minimized.

Copy link

wteja commented Sep 1, 2013

That great ! Thanks.

@nerdybird

This comment has been minimized.

Copy link

nerdybird commented Sep 30, 2013

Thank you.... Worked like a charm!

@Boblebad

This comment has been minimized.

Copy link

Boblebad commented Oct 17, 2013

I know i'm not the sharpest tool in the shed, but why go through all this to add more products to the page, when this is controlled by WP through settings/reading, where you just set the post count ?

If it says 10, then you will get 10 products displayed on your shop page, setting it to 12, gets you 12 a.s.o. :)

All the best
Carsten

@jake-lee

This comment has been minimized.

Copy link

jake-lee commented Oct 17, 2013

I'm new to PHP and I'm curious what the "20" is for in the snippet above?

Boblebad... I tried to change it the way you described and it didn't work for me so I had to use the snippet. I think that function is "Theme" sensitive but the

@ForestSkillsLtd

This comment has been minimized.

Copy link

ForestSkillsLtd commented Nov 11, 2013

Um... so under which heading in Woocommerce functions.php does this line of code go? Under;

function woocommerce_legacy_paypal_ipn() {
function woocommerce_template_redirect() {
function woocommerce_nav_menu_items( $items, $args ) {
function woocommerce_nav_menu_item_classes( $menu_items, $args ) {
function woocommerce_list_pages( $pages ){
function woocommerce_update_cart_action() {
function woocommerce_add_to_cart_action( $url = false ) {
function woocommerce_add_to_cart_message( $product_id ) {
function woocommerce_clear_cart_after_payment() {
function woocommerce_checkout_action() {
function woocommerce_pay_action() {
function woocommerce_process_login() {
function woocommerce_process_registration() {
function woocommerce_order_again() {
function woocommerce_cancel_order() {
function woocommerce_download_product() {
function woocommerce_readfile_chunked( $file, $retbytes = true ) {
function woocommerce_ecommerce_tracking_piwik( $order_id ) {
function woocommerce_products_rss_feed() {
function woocommerce_add_comment_rating( $comment_id ) {
function woocommerce_check_comment_rating( $comment_data ) {
function woocommerce_get_order_id_by_order_key( $order_key ) {
function woocommerce_track_product_view() {
function woocommerce_layered_nav_init( ) {
function woocommerce_layered_nav_query( $filtered_posts ) {
function woocommerce_price_filter_init() {
function woocommerce_price_filter($filtered_posts) {
function woocommerce_save_password() {
function woocommerce_save_address() {
function wc_get_product_terms( $product_id, $taxonomy, $args = array() ) {
function _wc_get_product_terms_parent_usort_callback( $a, $b ) {

@persianturtle

This comment has been minimized.

Copy link

persianturtle commented Nov 20, 2013

I'm no expert, but I believe you should include the code in your own theme/childtheme functions.php file. That way, when you update woocommerce, you won't overwrite your custom edits. The same goes for your theme. If you are using a theme you didn't create, then create a childtheme and include the code in your childtheme's function.php file. Hope this helps!

@chameleonwebservices

This comment has been minimized.

Copy link

chameleonwebservices commented Dec 19, 2013

You can change this dynamically without editing code using WordPress:-

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

The is the reading settings then Blog pages show at most ??

The default is 10.

You can edit this value to the required amount. 12 puts the amount on the page nicely.

The column count:-

templates/content-product.php

// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) )
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );

The number here is the total number of products in each line.

@GabrielGil

This comment has been minimized.

Copy link

GabrielGil commented Feb 20, 2014

I suggest you to update this code according to 2014 ^^.

add_filter( 'loop_shop_per_page', function ( $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.
    return 9;
}, 20 );
@orenshamai

This comment has been minimized.

Copy link

orenshamai commented Feb 23, 2014

works 100% - thx.

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 3, 2014

Great suggestion by chameleonwebservices. You don't need to mess around with Woocommerce files, just go into Options and change the reading settings to show any number you want. Default is usually set at 10. So if you want to show 20 products per listing, change 10 to 20. Note that this may or may not work depending on your setup or theme. But it worked with me. Thank you chameleon, thanks everyone.

@GitHubGreg

This comment has been minimized.

Copy link

GitHubGreg commented Jun 26, 2014

Is there a way to make a product taxonomy (a product category page) show more than the default 5 per page? This code doesn't work for that.

@technokey23

This comment has been minimized.

Copy link

technokey23 commented Aug 13, 2014

In my site during page load it displays 4 products in a row but after the page gets completely loaded it displays only 3 products. I have tried all above solutions but no success. Can anyone help me out?

@christyeller

This comment has been minimized.

Copy link

christyeller commented Aug 14, 2014

I too am looking to change the number of products displayed on the category page. I could write it myself, if I could just find where it is. Is there a category page template?

BTW, why is it "5"? Seems so random and such a small number and that doesn't work for a layout of 3 or 4 per row.

@mattrock1

This comment has been minimized.

Copy link

mattrock1 commented Sep 17, 2014

Works like a charm (WP 4.0, WC 2.2.3). Cheers!

@Fredbnm

This comment has been minimized.

Copy link

Fredbnm commented Nov 14, 2014

https://gist.github.com/GabrielGil thank man, you really helped me

@chrisreeves-

This comment has been minimized.

Copy link

chrisreeves- commented Dec 2, 2014

Awesome, thanks! Worked perfectly

@navneet2013

This comment has been minimized.

Copy link

navneet2013 commented Mar 7, 2015

i want my products to be displayed as per this website
http://www.claessons.com/produkter-list.asp?do=list&sokord=&category=&viewstyle= ,
I have made changes in my theme's archive-product page, but not able to get as required..my 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(); ?>

                    

                    <?php
                    /**
                     * 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; ?>
            </div>
        </div>
    </div>
@esucces

This comment has been minimized.

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?

@jnz31

This comment has been minimized.

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. url.com/?show=99 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..

@s2ar

This comment has been minimized.

Copy link

s2ar commented Oct 3, 2015

excellent

@safrasahamed

This comment has been minimized.

Copy link

safrasahamed commented Oct 10, 2015

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

Just added in this page
wp-admin/theme-editor.php?file=functions.php&theme=sw_maxshop&scrollto=144

@simarexpress

This comment has been minimized.

Copy link

simarexpress commented Nov 5, 2015

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

@hollyboom

This comment has been minimized.

Copy link

hollyboom commented Mar 30, 2016

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
}
}`

@mr-it-pro

This comment has been minimized.

Copy link

mr-it-pro commented May 20, 2016

Will this change stick after a WooCommerce update?

@Aravin

This comment has been minimized.

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.

image

@zoldos

This comment has been minimized.

Copy link

zoldos commented Oct 16, 2016

Worked great!

@GoldLeafx86

This comment has been minimized.

Copy link

GoldLeafx86 commented Nov 1, 2016

Thanks a lot ! that works like cream 👍

@imanuelgittens

This comment has been minimized.

Copy link

imanuelgittens commented Jan 3, 2017

Works beautifully. Thank you!

@KaoTupitec

This comment has been minimized.

Copy link

KaoTupitec commented Jan 11, 2017

Thanks :)!

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 21, 2017

@jameskoster Great It's working for me :)

@vivoeusebio

This comment has been minimized.

Copy link

vivoeusebio commented Mar 30, 2017

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 (https://www.elegantthemes.com/gallery/divi/) 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.

@darwing1210

This comment has been minimized.

Copy link

darwing1210 commented Apr 3, 2017

@vivoeusebio there is an option in the divi settings

@paaljoachim

This comment has been minimized.

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.

@keyurjay

This comment has been minimized.

Copy link

keyurjay commented Jul 26, 2017

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

@Josepek

This comment has been minimized.

Copy link

Josepek commented Aug 5, 2017

Oh! greats!
Thanks...

@angelique2017

This comment has been minimized.

Copy link

angelique2017 commented Oct 21, 2017

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.
https://wordpress.org/plugins/woocommerce-products-per-page/

@KristinUbute

This comment has been minimized.

Copy link

KristinUbute commented Mar 3, 2018

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 Wordpress.org 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.

Urgent

Thx
Kristin

@iiiGerardoiii

This comment has been minimized.

Copy link

iiiGerardoiii commented Aug 20, 2018

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.

@Krunal2070

This comment has been minimized.

Copy link

Krunal2070 commented Sep 10, 2018

Thanks Work for me.

@pablo-sg-pacheco

This comment has been minimized.

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;
} );
@gabriel-munteanu

This comment has been minimized.

Copy link

gabriel-munteanu commented Feb 7, 2019

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!

@peterg23

This comment has been minimized.

Copy link

peterg23 commented Apr 9, 2019

@pablo-sg-pacheco thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.