There is a lot of plugins available that makes this possible, but they are not for free, so I'm actually trying to restrict shop, checkout and cart page, just for people registered as customers, I test this code below on functions.php
file:
global $current_user;
get_currentuserinfo();
if (user_can( $current_user, "subscriber" ) && isset($_GET['page_id']) && $_GET['page_id'] > 0 && get_option( 'permalink_structure' )=="" && $_GET['page_id'] == woocommerce_get_page_id('shop') ) {
wp_redirect( home_url( '/customer-register' ) );
die();
}
But it's not working, maybe is more complex than I thought, do you have a solution for this?
You could try the following custom hooked function:
add_action( 'template_redirect', 'subscribers_redirection' );
function subscribers_redirection() {
if ( ( ! is_user_logged_in() || current_user_can( 'subscriber' ) )
&& ( is_shop() || is_product_category() || is_product_tag() || is_product() ) ){
wp_redirect( home_url( '/customer-register' ) );
exit();
}
}
Code goes in function.php file of your active child theme (or active theme).
It should work.
You don't need to restrict cart and checkout pages as if there is no products added to cart, nothing is displayed.