Especially when you have many WooCommerce product categories, it may happen some of them have a single product. Although this is a rare scenario, let’s see how easy it is to redirect customers directly to the single product page in case you don’t want them to see the category page first. Enjoy!

PHP Snippet: Redirect WooCommerce Product Category Page to Single Product Page
/**
* @snippet Redirect Product Cat to Product ID
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 7
* @community https://fa8faab2-7736-467b-aa28-860b32869022.express.conves.io/club/
*/
add_action( 'wp', 'bbloomer_redirect_cat_to_product' );
function bbloomer_redirect_cat_to_product() {
if ( is_product_category( 'tables' ) ) {
wp_safe_redirect( get_permalink( 123 ) ); // PRODUCT ID
exit;
}
}









Here I give you an improvement of the code that automates the whole process. I hope it helps you.
add_action('template_redirect', 'redireccionar_categoria_individual'); function redireccionar_categoria_individual() { if (is_product_category()) { global $wp_query; $categoria_actual = $wp_query->get_queried_object(); $productos = get_posts(array( 'post_type' => 'product', 'posts_per_page' => -1, 'product_cat' => $categoria_actual->slug )); if (count($productos) === 1) { $producto = $productos[0]; wp_redirect(get_permalink($producto->ID)); exit; } } }Haven’t tested it, but thank you!