change-products-per-page.php(file created)
| @@ -0,0 +1,9 @@ | |||
| 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 | + | ||
更新
更早