WooCommerce B2B: How to Set Up a Wholesale Store

The ecommerce sector is seeing incredible growth, year after year, with no foreseeable end in sight. The same is true for B2B ecommerce, yet there aren’t many good platform choices available for small-to-medium businesses that want to sell wholesale. There are several SaaS solutions on the market, but these are costly, closed-source, and mostly oriented towards larger businesses.

If you are a business owner or developer, WooCommerce is a solution that’s free, versatile and powerful. 

Is WooCommerce right for B2B shops?

“Out-of-the-box”, it isn’t. WooCommerce is a fantastic solution for ecommerce stores, but it wasn’t developed specifically for wholesale, so it lacks many important options at the outset. However, you can use a powerful wholesale plugin like B2BKing to extend WooCommerce and add all the business-to-business functionalities that you may need. 

There are two other aspects that you should be aware of when choosing WooCommerce for your B2B project:

  • WooCommerce will require regular plugin updates to ensure it’s secure and working correctly.
  • Depending on your hosting and website configuration, the WordPress environment can sometimes perform a little slowly. However, there are ways to optimize and speed it up such as through plugins like WP Rocket (or other caching and optimization plugins).

While it’s not perfect, WooCommerce is currently powering more than 20% of the world’s online stores, and there are good reasons for that: it’s free, open-source, powerful and secure. These same qualities also make it a great choice for wholesale stores.

How does a B2B store differ from a typical e-store?

Selling business-to-business is often a very different and more personal experience than selling directly to consumers. Business buyers are knowledgeable, open to negotiation, and want to get great offers and discounts for buying in bulk. Price catalogs, discount options and payment and shipping options can vary widely from customer to customer, depending on factors such as business size, order size or existing business relationships.

From a website development standpoint this translates into a necessity for a high degree of technical flexibility when it comes to pricing, discounts, shipping and order rules. 

Selling to businesses also introduces a need for features such as:

  • Hiding prices for guests
  • Business registration form 
  • VAT (or other tax ID) number support
  • Tax exemptions
  • Quote requests
  • Custom billing and checkout fields
  • Wholesale order form
  • Ability to support multiple users on a buyer account (for corporate structures)

Let’s go ahead and look at how a few of these features can be implemented in WooCommerce. The next sections will be geared more towards developers and I will share a few code snippets that I hope you will find helpful, as well as free plugins that you can use.

1. Hide prices for guest users

Let’s start off with an easy one. You can do this with two WooCommerce filters. First, let’s use woocommerce_get_price_html to change the displayed price to “Login to view prices”.

add_filter( 'woocommerce_get_price_html', 'b2bking_hide_prices_guest_users', 10, 2 );

function b2bking_hide_prices_guest_users( $price, $product ){
if ( ! is_user_logged_in() ){
	return esc_html__( 'Login to view prices', 'your-plugin-text-domain' );
} else {
	return $price;
}
}

Once we’ve done this, prices are no longer visible and will be replaced by our text. This is not enough though, since the user can still add these products to cart and see their price. A solution is provided to us by the aptly named woocommerce_is_purchasable filter.

add_filter( 'woocommerce_is_purchasable', 'b2bking_disable_purchasable_guest_users' );

function b2bking_disable_purchasable_guest_users( $purchasable ){
	if ( ! is_user_logged_in() ){
		return false;
	} else {
		return $purchasable;
	}
}

After you add this, products should no longer be purchasable by guest users and the “add to cart” button will no longer be available. One more thing that’s worth mentioning is that you may get into trouble when using AJAX search forms, depending on how those are set up. A quick way to get that fixed is to also add the above code to your main code and check for AJAX by wrapping the code inside:

if ( wp_doing_ajax() ){ 
// code here
}

The end result:

If you are interested in a plugin alternative because you’re not familiar with coding, B2BKing has this and other guest access restriction functionalities such as an option to hide the website entirely, or hide prices for individual products or categories.

2. Business registration, or separate B2B and B2C registration forms

What you want to do here is add custom fields such as “Company Name”, “Address”, “VAT ID”, etc.

You can use this code to add a custom field for company name:

add_action( 'woocommerce_register_form', 'b2bking_custom_registration_field' );

function b2bking_custom_registration_field(){
	echo '<label>' . esc_html__( 'Company name', 'your-custom-text-domain' ) . '</label>';
	echo '<input type="text" name="billing_company">';
}

If you want to sync this field with the WooCommerce billing field for company name on registration, you can do this by using the woocommerce_created_customer hook and saving the company name as user meta, using the same fields that WooCommerce uses: billing_first_name, billing_company, billing_city, etc:

add_action( 'woocommerce_created_customer', 'b2bking_save_custom_registration_fields' );

function b2bking_save_custom_registration_fields( $user_id ) {
$field_value = sanitize_text_field( filter_input( INPUT_POST, 'billing_company' ) ); 
if ( $field_value !== NULL ){
	update_user_meta( $user_id, 'billing_company', $field_value );
}
}

How can you create separate B2B and B2C form fields? You can add a “Select” field to registration in the way explained above and use a bit of JavaScript to determine whether the user chose “Individual” or “Company”. Show or hide registration fields like Company name depending on what the user chooses.

If you wish to avoid coding, there are some free plugin solutions to extend registration, such as https://wordpress.org/plugins/user-registration/ that also have options for multiple registration forms, though creating B2B-specific registration may require a little extra work on your side.

If you’re looking for a premium solution, B2BKing provides some handy, easy-to-use shortcodes that you can add to any page and create a business registration form

3. Wholesale order form

Business customers often know exactly what they want, down to the SKU, so adding a wholesale order form to your website makes it quick to order for your customers, and makes you look professional.

How can you add one? There’s no quick code snippet that can do this, so I think a plugin is your best solution.

There’s a free plugin that I personally tested, which looks and works great: https://wordpress.org/plugins/woocommerce-bulk-order-form/

B2BKing also has its own proprietary implementation, which you can see in the next image:

4. Wholesale price structure

The relevant question here is: how to set up different prices for different users? There are 2 ways to go about this: change the price directly, or add a discount.

To add a cart discount for a user or category of users, use this code:

add_action( 'woocommerce_cart_calculate_fees', 'b2bking_cart_discount' );

function b2bking_cart_discount( $cart ){
$cart->add_fee( 'B2B Discount', -10 );
}

The code above uses a bit of a trick by adding a negative fee, which is a discount. The code above doesn’t do much, it just adds a 10 dollar discount for all users. Let’s expand the code a little:

function b2bking_cart_discount( $cart ){
	$user_id = get_current_user_id();
	$user_status = get_user_meta( $user_id, 'user_status', true );
	if ( $user_status === 'b2b' ){
		$cart->add_fee( 'B2B Discount', -10 );
	}
}

How’s this? Now the code checks if the user’s meta status is ‘b2b’ and gives a discount only to b2b users.

How do you set the meta status? You could set that on registration using the woocommerce_created_customer hook that I used above in the 2nd article section, and a simple line of code. The function update_user_meta is used for both updating and creating user meta.

update_user_meta( $user_id, 'user_status', 'b2b' );

What if you want to set complex structures of different prices for different products for different users?

This gets a little more complicated but you can use the same principles. In WooCommerce, a product is a “post”, and you can set post meta data for it. For example, you can add a post meta named b2b_price, to have a separate price for b2b users. Here’s the code.

update_post_meta( $post_id, 'b2b_price', 15 ); // 15 is the price for b2b users

How do you show this price to b2b users only?

add_filter('woocommerce_product_get_price', 'b2bking_fixed_price', 99, 2 );
add_filter('woocommerce_product_get_regular_price', 'b2bking_fixed_price', 99, 2 );
add_filter('woocommerce_product_variation_get_regular_price', 'b2bking_fixed_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'b2bking_fixed_price', 99, 2 );

function b2bking_fixed_price( $price, $product ) {
	// check if the user is B2B or not
	$current_user_id = get_current_user_id();
	$current_user_status = get_user_meta( $current_user_id, 'user_status', true );
	if ( $current_user_status !== 'b2b' ){
		// if user is not b2b show the normal price
		return $price;
	} else {
		// get the current product’s price for B2B users
		$current_product_id = $product->get_id();
		$b2b_price = get_post_meta( $current_product_id, 'b2b_price', true );
		return $b2b_price;
	}
}

5. Setting up tax exemptions

This one’s easier than you think! There’s a very handy function that you can use in WooCommerce that will do this for you and even take care of price display in most situations: set_is_vat_exempt() . Good name, right?

This function will even make it so that B2B users see prices with the suffix “excluding tax”, while B2C users see prices saying “including tax”.

add_action( 'init', 'b2bking_tax_exemption' );

function b2bking_tax_exemption(){
	// first we check if the user is tax exempt
	$tax_exempt = get_user_meta( get_current_user_id(), 'is_tax_exempt', true );
	if ( $tax_exempt === 'exempt' ){
		$customer = WC()->customer;
		$customer->set_is_vat_exempt( true );
	} else {
		// the next line is only necessary if the user’s exempt status changes dynamically, such as based on billing country
		$customer->set_is_vat_exempt( false ); 
	}
}

B2BKing – WooCommerce B2B & Wholesale Plugin

I hope some of what I shared above will be helpful to you. Equipping WooCommerce with B2B functionalities is a complex task though, and I wouldn’t fault you if you decided buying a premium plugin is a better use of your time than writing the code yourself 🙂 Really, I won’t judge you at all.

With that in mind, I’ll share a few words about B2BKing. This is a project me and my team have been working on for a while, with the goal of turning WooCommerce into a capable B2B solution, an alternative to the costly SAAS platforms.

We’re constantly developing and supporting it as a long-term project, and it currently has more than 137 features including business registration, tax exemptions, dynamic pricing rules, VAT support, built-in messaging system, multiple buyers on account, offers, a dedicated B2B&B2C hybrid mode, and much, much more.

This week, we are proud to have been hand-picked by Envato as its Featured Plugin of the Week and showcased on the CodeCanyon front page.

We offer a live demo that you can test at any time, both backend and frontend: Live Demo

If you have any questions about the article, about the plugin, or just want to say hi, don’t be shy! Feel welcome to reach out to your friendly neighbourhood plugin developer.

Related content

  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you know, the WooCommerce My Account page, which contains the Login Username or email address * Password * Remember me Log in Lost your password? shortcode, has both Login and Registration forms when […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]
  • WooCommerce: Add Prefix / Suffix to Product Prices
    Sometimes you may want to add a prefix or a suffix to your prices. It could be something like “From…”, “Only…”, “…tax free” and so on. The first good news is this is very easy to do with a WooCommerce filter (remember, filters change the value of an existing variable, while actions add content). The […]

Stefan Statescu

Stefan Statescu is the team leader over at B2BKing. He loves WooCommerce, B2B, and adding value to businesses through awesome software.

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

14 thoughts on “WooCommerce B2B: How to Set Up a Wholesale Store

  1. B2B King looks awesome – and wayyyy more economical than trying to do/maintain similar functionality via custom code.

    Do you have any plans to add a stock management feature whereby you could allocate stock per user role? For example, so you could allocate 10 units for General Public, and 10 units for Retailers (or all B2B customers combined)? I would love to see this feature if it’s at all possible. It exists in the Woosuite Wholesale plugin from what I can see which is perhaps the only advantage it has over B2B King. Otherwise, B2B King is infinitely better across the board.

    1. Hi Kieran,
      Thanks for getting in touch,
      We actually are planning to add that kind of stock management option in the coming months. Here is a list with some of the features we’re looking to add this year: https://woocommerce-b2b-plugin.com/b2bking-in-2022-and-beyond-roadmap-and-improvements/

      Kind regards,
      Stefan

  2. Hi Paolo!

    I am currently deciding if implementing B2BKing to my next project, but I just want to know if this plugin has hooks docs and if I can use standard woocommerce hooks to extend functionality through filters and actions.

    1. The best thing would be asking the plugin devs. Let us know!

  3. i’m using b2bking from a month but i have problem with custom b2bking field and woocommerce field, they don’t sync and the thing is very strange.

    i aksed support day ago but nothing no reply.

    p.s. I asked to know if we can get a refound (request feature is very lack, we can’t convert request in order and conversatin feature is very basic without archive/user manage function) but month ago but nothing no replay.

    1. Hello Paolo, I find this weird. How did this end?

  4. Hello
    We use B2BKing Pro, and let the clients register sub-users to main account.
    But it askes them for their own adresses etc…Shouldnt this be automaticly taken from the main account?

    1. Not fully sure. What did the plugin support team say?

  5. Many thanks, too lot change code but I will see great plugin at the end 🙂

    1. Great!

  6. hi, does your plugin allow business ratings after every transaction?

    1. Hi, ask the developers please

  7. Hi,

    I want to make a store like AliExpess where user can create their own store and sell their products. Can you recommend any best Multi-vendor plugin?

Leave a Reply

Your email address will not be published. Required fields are marked *