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.
10 thoughts on “WooCommerce: Redirect single product pages to home page”
This snippet saved me alot of time and money.
it does the trick.
Thanks Sandesh!
I’m glad I was able to help. Thanks for the comment.
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.
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.
thank you, can i add this to only one category and not for all category products ?
Is it possible to change the home_url to the “add-to-cart url”?
The snippet worked. Thanks.
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.
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.
i dont know sould which file to add this code