
When managing a WooCommerce store, it’s common to rearrange products or remove them from certain categories. However, this can lead to an unexpected issue: paginated product category URLs (e.g., /product-category/shirts/page/3/
) may still be accessible even when that specific page no longer contains any products.
Instead of displaying a 404 error, it’s often better to redirect users back to the main category page to avoid confusion and improve user experience.
This is especially important for SEO, as you don’t want search engines indexing irrelevant or broken pages. The solution is to detect when a paginated product category archive is empty or invalid and redirect to the base category URL instead.
Below is a simple snippet you can add to your theme’s functions.php
or a custom plugin. It handles the redirect only when necessary, ensuring users and bots land on meaningful content.