Last active
September 19, 2024 12:40
-
-
Save jameskoster/1601682 to your computer and use it in GitHub Desktop.
WooCommerce - 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
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; | |
} |
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' );
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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!