Last active
February 27, 2022 00:14
-
-
Save woogists/e414d9463d8843bbe4efc4c4c519d888 to your computer and use it in GitHub Desktop.
[Theming Snippets] Change number of products displayed per page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
/**
*/
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;