use (.*) instead of * and if that doesn’t work then you can use WordPress hook template_redirect to redirect the page on specific conditions but it required a bit of coding knowledge.
hi thanks for your quick reply.
I’m afraid(.*) isn’t working.
I’ll look into the WordPress hook template_redirect.
thanks.
I’ve added the following function to function.php it works.
add_action( 'wp', 'ts_redirect_product_pages', 99 );
function ts_redirect_product_pages() {
if ( is_product() ) {
wp_safe_redirect( home_url('/shop/') );
exit;
}
}
You can use better code to avoid Fatal errors on plugin deactivate by checking function exists also you can fetch dynamic page id from the WC settings
/**
* Redirect WC product page to main shop page.
*/
function cusotm_wc_redirect_product_pages() {
if ( function_exists( 'is_product' ) ) {
if ( is_product() ) {
$shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
wp_safe_redirect( $shop_page_url );
exit;
}
}
}
add_action( 'template_redirect', 'cusotm_wc_redirect_product_pages', 99 );
Hi @foodstijl,
Sorry for the inconvenience caused.
I have checked and it is working. You can check this screen record.
Hope this will help you. Let us know how it goes.
Thanks!
I see. thanks.
I will use your code!
-
This reply was modified 4 years, 5 months ago by
foodstijl.
Hi @foodstijl,
Hope you are doing well.
Can you please inform me that is your above-mentioned issue already fixed or not?
Let us know the update. Thanks!
Hi @foodstijl,
We haven’t heard back from you in a long time. So, I am assuming your issue has been resolved. I am closing this topic.
Have a nice day!