How to Make a WooCommerce Store B2B Only?
Today we will table how to make your woocommerce store for the b2b to customer only. Sometimes, you need to put your store for login customers or registered customers only. This example will help you make your woocommerce for b2b customers. So, let’s start with an example.
You need to add a hook in initialization to check whether the customer is logged in or not.
add_action( 'init', 'qaisarsatti_store_redirect' );
Now redirect the customer to the login page if not logged in.
function qaisarsatti_store_redirect() {
if ( !is_user_logged_in() ) {
$loginUrl = wp_login_url();
$currentUrl = home_url($_SERVER['REQUEST_URI']);
if($loginUrl!=$currentUrl) {
wp_redirect( wp_login_url());
exit;
}
}
}
if ( !is_user_logged_in() ) {
$loginUrl = wp_login_url();
$currentUrl = home_url($_SERVER['REQUEST_URI']);
if($loginUrl!=$currentUrl) {
wp_redirect( wp_login_url());
exit;
}
}
}