Fix Pagination (page/2/) 404 Errors on WooCommerce Archives

Quick Summary
- In a pre_get_posts callback, set posts_per_page on product_cat archives to the number of products your template shows, 8 in the example.
- The 404s appear when the template shows a different product count per page than the main query, which decides whether a page exists.
- Add && $query->is_main_query() to the condition, since without it the change can also affect other queries on product category pages.
On WooCommerce product category archives, /page/2/ and higher can return a 404 error even though a pagination plugin like WP-PageNavi shows links to them. This usually happens when the template displays a different number of products per page than the main query uses. WordPress decides whether a page number exists from the main query, so if the main query has fewer pages than the pagination links point to, the extra pages return 404.
The fix is to set the number of products per page on the main query itself. Add this to your child theme’s functions.php:
//Product Cat Pagination
function modify_product_cat_query( $query ) {
if (!is_admin() && $query->is_tax("product_cat")){
$query->set('posts_per_page', 8);
}
}
add_action( 'pre_get_posts', 'modify_product_cat_query' );How it works
pre_get_postsruns before WordPress queries the database, so the change applies to the query that decides pagination.! is_admin()keeps the change off admin screens, and$query->is_tax( "product_cat" )limits it to product category archives.8is the number of products per page. Use the same number your template displays.- For a different archive, change the condition, for example
$query->is_tax( 'product_tag' )for product tags or$query->is_category()for post categories.
The condition doesn’t check $query->is_main_query(), so it can also change other queries that run on a product category page. Adding && $query->is_main_query() to the if limits it to the main query. The same hook lets you change the main query in other ways, such as hiding a post from the homepage.
Related articles
- numbered pagination for a custom WP_Query: when the list comes from your own query, not the main one
- 404 errors on custom post type pages: a different cause, fixed by flushing the rewrite rules

