Menu Close

WooCommerce: Redirect Product Category Pages

default

Maybe because you have only one product category and therefore search engines would find duplicate content (Shop page = Category page) and penalize your website.

Or maybe because you use advanced product filters and you prefer customers to see the filtered view “by category” (e.g. “example.com/shop/?_product_category=tables“) as opposed to the default category pages ( “example.com/product_category/tables” ).

Either way, it is possible to programmatically redirect all product category pages to a given page or to a relevant URL with parameters – and here’s the fix. Enjoy!

Product categories come with their own page. But sometimes you may want to unindex + redirect these pages for SEO reasons. Here are two solutions to redirect all pages to the Shop page, or to a category-specific URL with parameters

PHP Snippet 1: Redirect All Product Category Pages to Shop Page

/**
 * @snippet       Redirect To Shop @ WooCommerce Category Pages
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'wp', 'bbloomer_redirect_cats_to_shop' );

function bbloomer_redirect_cats_to_shop() {
	if ( is_product_category() ) {
      wp_safe_redirect( wc_get_page_permalink( 'shop' ) );
      exit;
   }
}

PHP Snippet 2: Redirect Each Product Category Page to A Relevant URL With Parameters

/**
 * @snippet       Redirect To URL + Parameters @ WooCommerce Category Pages
 * @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_relevant_filter' );

function bbloomer_redirect_cat_to_relevant_filter() {
	if ( is_product_category() ) {
		$term = get_queried_object();
		$url = $term && $term->slug ? '/shop/?_product_category=' . $term->slug : wc_get_page_permalink( 'shop' );	
         wp_safe_redirect( $url );
         exit;
   }
}
View Source
Posted in WooCommerce Tips