Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active February 27, 2022 00:14
Show Gist options
  • Save woogists/e414d9463d8843bbe4efc4c4c519d888 to your computer and use it in GitHub Desktop.
Save woogists/e414d9463d8843bbe4efc4c4c519d888 to your computer and use it in GitHub Desktop.
[Theming Snippets] Change number of products displayed per page
/**
* 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 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;
}
@mmh4560
Copy link

mmh4560 commented Jan 22, 2019

If I use $cols = 12; instead of $cols = 9;.
Why It's not working in my WordPress Divi theme ??

@sreygel
Copy link

sreygel commented Feb 15, 2019

I have the same problem... :(

@cesarguillenf
Copy link

same problem

@JasonS1995
Copy link

Guys, in Divi, this snippet doesn't work, however you can easily change the number of products in the Divi Theme options on the General Tab.

@domaingood
Copy link

@cesarguillenf
Try Divi Theme Options =>
Number of Products displayed on WooCommerce archive pages

@betharte7
Copy link

Thank you very much. I've changed the product number per page in the Divi Theme Options and it works fine.

@AT4MO
Copy link

AT4MO commented Aug 3, 2020

hello, how i can use that for display product at mobile? 4 mobile 5 desktop ?¿

ty

@ComputersHowtoPro
Copy link

ComputersHowtoPro commented Feb 27, 2022

The description of this snippet in the original woocommerce docs is simply WRONG.
$cols DOES NOT decide the number of products, it decides the NUMBER OF COLUMNS in which the products are displayed.
Why do you think it's called $COLS, not $nproducts or similar ? Because it's about the NUMBER OF COLUMNS !
So this here:
https://woocommerce.com/document/change-number-of-products-displayed-per-page/
should be changed to read something like:
/**

  • Change number of COLUMNS for displaying the products (shop 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 COLUMNS in which the number of products based on the value stored on Options –> Reading is displayed , so let's say you have 9 posts in Reading settings, and 3 as $cols here, that will display 9 products in 3 rows of 3 products each !
// Return the number of COLUMNS PER ROW you wanna show ON THE SHOP PAGE
$cols = 3;
return $cols;

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