Sandesh

April 11, 2020

WooCommerce: Redirect single product pages to home page

Do you want to redirect product pages to the home page or any other page? Well, this small snippet will help you. You don’t need to use any plugin. This little snippet will do the work.

/**
 * @snippet       WooCommerce Redirect single product pages to home page
 * @author        Sandesh Jangam
 * @donate $7     https://www.paypal.me/SandeshJangam/7
 */

add_action( 'wp', 'ts_redirect_product_pages', 99 );

function ts_redirect_product_pages() {
  	
	if ( is_product() ) {
		wp_safe_redirect( home_url() );
		exit;
	} 
}

// PS. - You can replace home_url() to your specific URL also.

Where to add custom PHP code?

Add the above PHP code at the end of to your child theme’s functions.php. There are many ways to add custom PHP code ( custom functionality ) to WordPress / WooCommerce website. Read this article for more information

Why this code is not working?

If you face any issue with the above code, then please let me know in the comment. I will be happy to review the code, and If it is working for you, then show me some love in the comment section.

Thank you in advance…!

Sharing is Caring!
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

About the Author

Sandesh Jangam is Developer, WooCommerce Expert, and Podcaster. He is working as a WordPress developer since 2014 and helping people with this blog. He loves to travel ancient temples, chilling at the beach and reading books

Join 1,000+ Subscribers

Get exclusive access to WordPress, WooCommerce tips, articles, tutorials right in your inbox.​

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

10 thoughts on “WooCommerce: Redirect single product pages to home page”

  1. Nice tutorial,
    thanks for source.

    Need some help,

    Is this possible, when we click “Buy Now” on the shop page, it will auto redirect to simple_page/contactpage? https://prnt.sc/uzifqb

    I have used this: https://prnt.sc/uziglf for “Add to cart” go to redirect simple_page/contact page

    I want for use, also Buy now go to the same page, how it’s possible.

    NB: Only for some products.

    1. It is definitely possible. You can add Buy Now button using some hook. Just append it before Add to cart with direct contact page link. You can contact me for custom work. Thanks.

  2. It would have been helpful if you’d added a little bit of an explanation as to how this snippet works. So that we could tweak it if needed.

    It looks as though the code is a generic code to redirect ALL product pages to the Home page (or whatever other page). I want to redirect ONE SPECIFIC page to a different Thank You page. I would have used this coding, but my knowledge is too limited to understand how to tweak it to achieve what I want.

    1. Thanks for your suggestion, I will consider this for next snippets.

      What you are looking for is redirect to different thank you pages? Am I right?
      Probably, I will make a snippet in future.

Leave a Comment

Your email address will not be published.

Become a WooCommerce Customization Expert and Earn More​

Get an early access notification right in your inbox.

Learn More or Register Now >>>