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

4 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.

Leave a Comment

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

Become a WooCommerce Customization Expert and Earn More​

Get an early access notification right in your inbox.

Learn More or Register Now >>>