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…!

Join 1,000+ Subscribers

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

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

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

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Recommended Articles