How to disable / hide a single woocommerce product page?

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

+6


source to share


6 answers


You can remove an anchor created on a store page that will never redirect the user to one page. To do this, you need to paste this code into your functions.php file.

remove_action( 
  'woocommerce_before_shop_loop_item',
  'woocommerce_template_loop_product_link_open',
  10
);

      



This code will remove the link, but after that you will also remove the closing anchor tag, only it will not break your HTML

remove_action(
  'woocommerce_after_shop_loop_item',
  'woocommerce_template_loop_product_link_close',
  5
);

      

+11


source


Place it in functions.php



//Removes links
add_filter( 'woocommerce_product_is_visible','product_invisible');
function product_invisible(){
    return false;
}

//Remove single page
add_filter( 'woocommerce_register_post_type_product','hide_product_page',12,1);
function hide_product_page($args){
    $args["publicly_queryable"]=false;
    $args["public"]=false;
    return $args;
}

      

+11


source


You can register a hook that returns 404 in case of pages with a is_product()

helper function

function prevent_access_to_product_page(){
    global $post;
    if ( is_product() ) {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
    }
}

add_action('wp','prevent_access_to_product_page');

      

The solution has been tested and works.

Note. The solution was somehow based on some information from @ale's answer.

+4


source


The only page is the one provided by WordPress and there is no way to disable it. But there are some ways to prevent access to one product page.

The first one is to edit your store template (products-archives) and delete all places where you have a link to one page.

Second, to check every page load if the page is a separate product page and redirects 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
    }
}

      

This code can be included in the functions.php file of the child-themes directory. Please be aware that I have not tested the code.

+2


source


Add this code to the themes functions.php file of your active child theme (or theme) and save the file.

remove_action ('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);

remove_action ('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5);
0


source


remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );

      

0


source







All Articles