Skip to content

Instantly share code, notes, and snippets.

@jameskoster
Last active March 8, 2025 09:34
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;
}
@gabriel-munteanu
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!

@peterg23
Copy link

peterg23 commented Apr 9, 2019

@pablo-sg-pacheco thank you!

@PaolaGress
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.

@gabriel-munteanu
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. https://developer.wordpress.org/themes/advanced-topics/child-themes/
Hope this helps!

@amirshnll
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' );
    }
}

@ajbanx
Copy link

ajbanx commented Mar 8, 2025

@nagpai figured it out!
It's the Jetpack "default" setting that isn't the default setting.

Workaround for now is to Get to Jetpack settings and set Infinite scroll settings
Writing tab
Load more posts using the default theme behaviour
(the default has the 2nd radial check)

https://user-images.githubusercontent.com/4162931/101133960-a8e6e880-362f-11eb-8a01-8bbc9c9d7746.jpg

@ajbanx
Copy link

ajbanx commented Mar 8, 2025

@nagpai figured it out!
It's the Jetpack "default" setting that isn't the default setting.

This removes the "More Products" and shows all products per Category

Workaround for now is to Get to Jetpack settings and set Infinite scroll settings
Writing tab
Load more posts using the default theme behaviour
(the default has the 2nd radial check)

https://user-images.githubusercontent.com/4162931/101133960-a8e6e880-362f-11eb-8a01-8bbc9c9d7746.jpg

@ajbanx
Copy link

ajbanx commented Mar 8, 2025

@nagpai figured it out!
It's the Jetpack "default" setting that isn't the default setting.

This removes the "More Products" and shows all products per Category

Workaround for now is to Get to Jetpack settings and set Infinite scroll settings
Writing tab
Load more posts using the default theme behaviour
(the default has the 2nd radial check)

https://user-images.githubusercontent.com/4162931/101133960-a8e6e880-362f-11eb-8a01-8bbc9c9d7746.jpg

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