Automatically Redirect From WooCommerce Products to Shopify Collections

Automatically Redirect From WooCommerce Products to Shopify Collections

Sometimes you need to redirect from Product pages to Collection pages.

We recently did an ecommerce website migration from WooCommerce to Shopify.

The old WooCommerce website had thousands of products, with many product categories.

On the new Shopify website, they had a few hundred products, with the same product Collections (product categories are called ‘Collections’ in Shopify).

So we decided to create “301 Redirects” from WooCommerce product pages to Shopify Collection pages.

We created a redirect script with this logic:

  1. On product page, get product’s category
  2. Find product category ‘slug’ (which is the short url of the category)
  3. Redirect to new website using category slug

This assumes that the url of Product Categories on old WooCommerce website is the same as the ‘slug’ of the Collection on the new Shopify website.

We added this code to the ‘header.php’ file on the WordPress WooCommerce site. Replace “” with your new website domain name:

<?php //setup redirect for product pages - to relevant category page on new website if ( is_product() ){ global $post; $terms = get_the_terms( $post->ID, 'product_cat' ); $product_cat_id; foreach ($terms as $term) { $product_cat_id = $term->term_id; break; } function woocommerceCategorySlug( $id ){ $term = get_term_by('id', $id, 'product_cat', 'ARRAY_A'); return $term['slug']; } $categoryurl = woocommerceCategorySlug($product_cat_id); wp_redirect( '' . $categoryurl, 301 ); exit; } ?>

Streamline your eCommerce Website Migration 

If you're navigating the complexities of transitioning from WooCommerce to Shopify and need expert assistance, we're here for you!

Contact us now to discuss how our team can efficiently manage your product page redirects, ensuring a seamless transition and improved user experience.

Why Shop Innovator?

          Join Us for a Free 30-minute Discovery Call—Let's Work Together to Improve Your Business!

          About the author: Yar Dev

          Experienced Shopify developer with a passion for creating stunning online stores.  Dedicated to delivering seamless shopping experiences and driving business success.
          Back to blog