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?
From the admin panel, go to WooCommerce > Product Visibility > Global visibility tab and select the product and category you want to hide.
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.
Go to Settings > Category Excluder. Checkmark the categories you want to hide. Click on Update.
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.
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…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With