change-products-per-page.php
· 454 B · PHP
Brut
add_action( 'pre_get_posts', 'custom_woocommerce_products_per_page' );
function custom_woocommerce_products_per_page( $query ) {
// Check if we're on a WooCommerce shop page or product category or tag page and if it's the main query
if( !is_admin() && $query->is_main_query() && (is_woocommerce() || is_product_category() || is_product_tag()) ) {
$query->set( 'posts_per_page', 9 ); // Set the number of products per page to 12
}
}
| 1 | add_action( 'pre_get_posts', 'custom_woocommerce_products_per_page' ); |
| 2 | |
| 3 | function custom_woocommerce_products_per_page( $query ) { |
| 4 | // Check if we're on a WooCommerce shop page or product category or tag page and if it's the main query |
| 5 | if( !is_admin() && $query->is_main_query() && (is_woocommerce() || is_product_category() || is_product_tag()) ) { |
| 6 | $query->set( 'posts_per_page', 9 ); // Set the number of products per page to 12 |
| 7 | } |
| 8 | } |
| 9 | |
| 10 |