Disable Shop page on Woocommerce to protect categories

To disable the shop page, copy over the archive-product.php file from the /wp-content/plugins/woocommerce/templates/archive-product.php and put in /wp-content/themes/{Your Theme}/woocommerce/archive-product.php

Open up the file and overwrite everything in file with the following code below:

<?php
global $wp_query;

$wp_query->set_404();
status_header(404);

get_template_part('404');

Save the file, and now your Shop page is gone and replaced with a 404 Page!


Add this to functions:

function woocommerce_disable_shop_page() {
    global $post;
    if (is_shop()):
    global $wp_query;
    $wp_query->set_404();
    status_header(404);
    endif;
}
add_action( 'wp', 'woocommerce_disable_shop_page' );

Docs: WooCommerce Conditional Functions Documentation


WooCommerce has a filter for the array that it uses to create the Product post type: woocommerce_register_post_type_product.

Rather changing the archive template to force it to redirect, you can completely remove the post type’s archive, but changing the has_archive attribute on the post type on creation.

add_filter('woocommerce_register_post_type_product', function($post_type) {
    $post_type['has_archive'] = false;
    return $post_type;
});

You should then remove the shop page in the CMS by going to WooCommerce » Settings » Product » Display, and clicking the “x” on the “Shop Page” option.

You might need to flush the permalink cache, which you can do just by clicking the “Update” button in Settings » Permalinks.