Set Products Per Page Conditionally in WooCommerce

Use 1 of these 3 PHP code snippets at the end of your child themes functions file to set products per page on WooCommerce archive page types including your shop, product category and product tag archive pages :

add_filter( 'loop_shop_per_page', 'products_per_page_category', 20 );
function products_per_page_category( $count ) {

    if ( is_product_category() ) {
    
        return -1; // Display all products
    }
    
    return $count; // For other pages, keep the default number of products per page
    
}

You can also use the woocommerce_product_query action hook to do exactly the same thing :

add_action( 'woocommerce_product_query', 'display_all_products_on_category_pages' );
function display_all_products_on_category_pages( $query ) {

    if ( ! is_admin() && $query->is_main_query() && is_product_category() ) {

        $query->set( 'posts_per_page', -1 );

    }

}

You can also use pre_get_posts to get the same result :

add_action( 'pre_get_posts', 'display_all_products_on_category_pages' );
function display_all_products_on_category_pages( $query ) {

    if ( ! is_admin() && $query->is_main_query() && is_product_category() ) {

        $query->set( 'posts_per_page', -1 );

    }

}

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.