woocommerce offtopic - Redirect the single product page link to the shop page

I am using the WooCommerce plugin.I want to redirect the user to shop page if they try to access the product link.For e

I am using the WooCommerce plugin.
I want to redirect the user to shop page if they try to access the product link.

For example, this is the product link: and shop page link:

Now when a user tries to visit a product link, should be redirected to the shop page!

Mainly, I don't want anyone to have an access to the product page!

Please, can someone tell me how can I achieve this?

Thanks in advance!

I am using the WooCommerce plugin.
I want to redirect the user to shop page if they try to access the product link.

For example, this is the product link: http://www.example/product/av and shop page link: http://www.example/shop

Now when a user tries to visit a product link, should be redirected to the shop page!

Mainly, I don't want anyone to have an access to the product page!

Please, can someone tell me how can I achieve this?

Thanks in advance!

Share Improve this question edited Nov 24, 2018 at 7:24 SherylHohman 8319 silver badges14 bronze badges asked Feb 15, 2018 at 10:15 HimaniHimani 371 gold badge1 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

You can try using template_redirect action hook to check if the current page is product page and after that, you can redirect the user to your shop page.

Paste this code into your functions.php

add_action('template_redirect','custom_shop_page_redirect');
function custom_shop_page_redirect(){
    if (class_exists('WooCommerce')){
        if(is_product()){
            wp_redirect(home_url('/shop/'));
            exit();
        }
    } 
    return;
} 

I have not tested it, but hope it will work for you.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742387475a4434346.html

相关推荐

  • woocommerce offtopic - Redirect the single product page link to the shop page

    I am using the WooCommerce plugin.I want to redirect the user to shop page if they try to access the product link.For e

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信