This code is perfect for what I needed. Out of the box it worked except for when a non-logged-in user searches directly for a product.So, just copy and pasted the if statement in your first function for every subcategory or product I needed restricted.
function woocommerce_hide_non_registered() {
if( ( is_product_category(‘display’) ) && ! ( current_user_can( ‘wholesale_customer’ ) || current_user_can( ‘administrator’ ) ) ) {
wp_redirect( site_url( ‘/’ ));
exit();
}
I changed is_product_category to is_product and it worked for products to. If you have a lot of products you have to do an if statement for every one.