How to disable/hide woocommerce single product page?

后端 未结 5 1958
北海茫月
北海茫月 2020-12-14 13:09

I am trying to hide the single product detail page on my wordpress-woocommerce site. How can i achieve this without breaking woocommerce functionality?

5条回答
  •  死守一世寂寞
    2020-12-14 13:33

    The single page is something that is provided from WordPress and there is no way to disabled it. But there some ways to prevent access to single product page.

    The first one is to edit your shop (products-archive) template and to delete all the places where you have a link to the single page.

    The second is to do a check on each page load if the page is a single product page and redirect the user to wherever you want:

    add_action('init','prevent_access_to_product_page');
    function prevent_access_to_product_page(){
        if ( is_product() ) {
            wp_redirect( site_url() );//will redirect to home page
        }
    }
    

    You can include this code in your functions.php file of your child-themes directory. Have in mind that I've haven't tested the code.

提交回复
热议问题