Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable/hide woocommerce category page?

I used the following code to hide the single product pages on woocommerce, which worked perfectly. Anyone trying to access single product pages are redirected to the home page.

I now want to hide the category pages. I dont need these as I am using the category shortcode to display product on other pages. Can anyone help with the required code?

//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;
}

Taken from: How to disable/hide woocommerce single product page?

like image 550
Zed0121 Avatar asked Nov 30 '17 16:11

Zed0121


People also ask

How do I hide categories from being displayed on shop page WooCommerce?

From the admin panel, go to WooCommerce > Product Visibility > Global visibility tab and select the product and category you want to hide.

How do I make categories private in WooCommerce?

To do this, go to the WooCommerce settings page and select the 'Privacy' tab. From here, you can select the 'Private' option for each category. If you want to make sure that only certain people can see certain products in your WooCommerce store, then you can make use of the Private Categories feature.

How do you hide categories on pages?

Go to Settings > Category Excluder. Checkmark the categories you want to hide. Click on Update.

How do I show product categories on WooCommerce shop page?

Show Product Categories on Shop PageClick on Appearance > Customize. Then go to WooCommerce > Product Catalog. Select “Show categories” from Shop Page Display. Click on Save Changes.


1 Answers

You could try to use this custom function, that will redirect to shop page, when a product category archive page is called:

add_action( 'template_redirect', 'wc_redirect_to_shop');
function wc_redirect_to_shop() {
    // Only on product category archive pages (redirect to shop)
    if ( is_product_category() ) {
        wp_redirect( wc_get_page_permalink( 'shop' ) );
        exit();
    }
}

Code goes in function.php file of your active child theme (or active theme) or in any plugin file.

Tested and works

As I don't think that you want to disable product categories functionality, but just the related archive page…

like image 77
LoicTheAztec Avatar answered Sep 22 '22 09:09

LoicTheAztec