-1

I want to redirect all single product page whose first link URL is "product" which will be redirected to store thank you page. I want to keep the single products, I just want the product with the path /product/ at the beginning to redirect. Since I'm currently using a product that doesn't have /product/, I need to remove from duplicate.

For example:

domain.com/product/category/product-name

domain.com/product/product-name

move to

domain.com/shop
halfer
  • 19,824
  • 17
  • 99
  • 186
Duc Phuli
  • 219
  • 1
  • 3
  • 13

1 Answers1

1

Based on WooCommerce: Single Product Page Redirect for Logged In Customers the following snippet should work for all your single product pages:

add_action( 'template_redirect', 'bbloomer_single_product_redirect );
 
function bbloomer_single_product_redirect() { 
    if ( ! is_product() ) return;  
    wp_safe_redirect( '/shop' );
    exit;
}
businessbloomer
  • 1,115
  • 7
  • 11
  • Oh @businessbloomer , I also like your blog, Sorry I didn't explain correctly. I want to keep the single products, I just want the product with the path /product/ at the beginning to redirect. Since I'm currently using a product that doesn't have /product/, I need to remove from duplicate – Duc Phuli Oct 12 '21 at 10:39
  • 1
    Gotcha. You can use the same snippet and also check if the current URL contains /product/ - and only then do the redirect: https://stackoverflow.com/questions/7118823/check-if-url-has-certain-string-with-php – businessbloomer Oct 12 '21 at 11:52