Menu Close

WooCommerce: Redirect Specific Category To Product Page

default

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!

This 1-product product category page is such a waste of white space and an extra click. Let’s get the customer straight to the single product page!

PHP Snippet: Redirect WooCommerce Product Category Page to Single Product Page

/**
 * @snippet       Redirect Product Cat to Product ID
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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;
	}
}
View Source
Posted in WooCommerce Tips