Disable “Single Product Page” in WooCommerce and Redirect

The Below code will completely disable users from accessing the Single Product Page in WooCommerce. Any single product page links will return 404.

/* Redirect Single Product Links to 404 */
function wpflt_prevent_access_to_product_page(){
    global $post;
    if ( is_product() ) {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
    }
}
add_action('wp','wpflt_prevent_access_to_product_page');

If you want to redirect any links to the single product page, to the Home Page, use the code below instead of above.

/* Redirect Single Product Links to Home Page */
function wpflt_prevent_access_to_product_page(){
    global $post;
    if ( is_product() ) {
        $target = get_option('siteurl');
        $status = '301';
        wp_redirect($target, 301);
        die();
    }
}
add_action('wp','wpflt_prevent_access_to_product_page');

If you are using WooCommerce this way, make sure your users won’t find any direct product links from the Shop Archive Page to the product page.

Also Read,

Disable Link to WooCommerce Single Product Page from Shop Archive Page.

Also, make sure you have Disallowed /product/ in robots.txt