Qaisar satti Blog
  • Home
  • Free Extensions
  • Tutorial
    • Magento 1
    • Magento 2
    • WooCommerce
    • Prestashop
    • Extension Review
  • Ask Questions
  • About
  • Contact

How to Make a WooCommerce Store B2B Only?

  • Qaisar Satti|
  • April 17th, 2024|
  • WooCommerce

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;
}
}
}

Related Posts:

  • How to Hide Prices from Guest Users in WooCommerce
  • 5 Best WooCommerce B2B Plugins – 2023
  • How to Allow Product Purchase to Customer Once in a Lifetime
  • How to Create Customer User Programmatically:
  • 5 Best WooComerce Product Addons Plugins

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

  • Stack overflow
  • Magento stackexchange
  • Quora
  • Magento Community

Suggested Products

  • B2B for WooCommerce

  • Request a Quote for WooCommerce

  • WooCommerce Advanced Product Quantity

  • WooCommerce Role Based Pricing

    WooCommerce Role Based Pricing

Recent Blogs

  • How to Add a Countdown Timer for Discounted Products in WooCommerce
  • How to Automatically Apply a Discount Coupon to the Cart in WooCommerce
  • How to Create Virtual Product Variations in WooCommerce Programmatically
  • How to Create Physical Product Variations in WooCommerce Programmatically
  • How to Hide Prices from Guest Users in WooCommerce
  • How to Display Custom Stock Status on Product Pages in WooCommerce
  • How to Add a Custom Shipping Method for WooCommerce
  • How to Create Coupons Programmatically in WooCommerce
  • How to Add Quantity Based Discounts in WooCommerce Programmatically
  • How to Add Custom Checkout Fields to WooCommerce Programmatically
  • How to Add Custom Registration Form Fields in WooCommerce
  • How to Create Custom or Sequential Order Numbers Programmatically
  • How to Display WooCommerce Categories in Your Menu
  • How you can Create User with All the Data Programmatically:
  • How to Create Admin User Programmatically:

Categories

  • Magento 2 (154)
  • WooCommerce (117)
  • WordPress (70)
  • Prestashop (15)
  • Extension Review (7)
  • Magento 1 (5)
  • Magento (3)

Post navigation

  • Stack overflow
  • Magento stackexchange
  • Quora
  • Magento Community

© Copyrights 2025. All rights reserved.