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;
}
@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