Create a B2B area on WooCommerce with pro accounts

Creating a B2B area on WooCommerce with trade accounts

To sell to businesses on a WooCommerce shop that already sells to consumers, you need three building blocks: a form that creates accounts with a “Pro” role, prices reserved for that role, then a few B2B rules. Everything can be done with free plugins, plus a few lines of code for the finer rules.

In short

  • User Registration creates a sign-up form that assigns the “Pro” role.
  • Role Based Pricing (free) or YITH Role Based Prices (paid) set the prices for this role.
  • A role can change automatically based on the amount purchased.
  • Four code snippets: minimum order, hidden categories, Company column, payment methods by role.
  • The snippets are compatible with WooCommerce HPOS order storage.

1. A form to create pro accounts

Two free plugins are enough:

Remember to ask for the company name, the SIREN number (French company ID) and the VAT number at sign-up: since the e-invoicing reform, this information is required to invoice a business.

Watch the pro account form on YouTube

2. Prices reserved for the Pro role

With the free plugin

Role Based Pricing for Woo, already installed at step 1, sets prices by role or by customer, product by product or for whole categories. It can also hide prices or block purchases for visitors who are not logged in. Percentage discounts and minimum or maximum quantities by role come with its paid version.

Watch the pro pricing setup, free version

With the paid YITH plugin

YITH WooCommerce Role Based Prices goes further:

  • global rules across the whole shop, as a percentage or in euros, or product by product;
  • different prices for your partners, resellers or members;
  • hiding prices and the “Add to cart” button for certain roles or for visitors without an account.

It does not create a role: add your “Professional” role with the free Members plugin.

Watch the pro pricing setup, premium version

For a fuller B2B catalog (bulk order form, quotes, payment terms per customer), a dedicated plugin such as B2BKing brings everything together in one tool.

3. Change the role automatically

An example: when a pro customer reaches €1,000 of purchases, they move to the “Pro 2” role, which gets larger discounts, set as in step 2. This is what YITH Automatic Role Changer for WooCommerce does.

Watch the automatic role change on video

4. Four B2B rules in a few lines of code

Paste these snippets into the functions.php file of your child theme or into the Code Snippets plugin. Replace pro with the identifier of your role. They also work on a standard shop.

Set a minimum order for pros

On one client’s site, pro accounts could only order from €450 excl. VAT. The message shows in the cart and blocks the order until the amount is reached:

add_action( 'woocommerce_check_cart_items', 'wycan_minimum_commande_pro' );
function wycan_minimum_commande_pro() {
    $minimum = 450;
    $roles   = (array) wp_get_current_user()->roles;

    if ( ! in_array( 'pro', $roles, true ) || ! WC()->cart ) {
        return;
    }

    $total = (float) WC()->cart->get_cart_contents_total();

    if ( $total < $minimum ) {
        wc_add_notice(
            sprintf(
                'Pro accounts order from %s excl. VAT. Your cart: %s excl. VAT.',
                wc_price( $minimum ),
                wc_price( $total )
            ),
            'error'
        );
    }
}

Hide categories from pros

add_action( 'pre_get_posts', 'wycan_masquer_categories_pro' );
function wycan_masquer_categories_pro( $query ) {
    if ( is_admin() || ! in_array( 'pro', (array) wp_get_current_user()->roles, true ) ) {
        return;
    }

    $liste_produits = 'product' === $query->get( 'post_type' )
        || ( $query->is_main_query() && $query->is_tax( array( 'product_cat', 'product_tag' ) ) );

    if ( ! $liste_produits ) {
        return;
    }

    $tax_query   = (array) $query->get( 'tax_query' );
    $tax_query[] = array(
        'taxonomy' => 'product_cat',
        'field'    => 'term_id',
        'terms'    => array( 10, 20, 30 ),
        'operator' => 'NOT IN',
    );
    $query->set( 'tax_query', $tax_query );
}

Replace 10, 20, 30 with the IDs of the categories to hide. This code removes the products from listings; someone who knows the exact address of a product can still open it.

Show the company in the order list

A “Company” column in the order list shows at a glance which pro customer placed the order. It uses the Company field entered at checkout and can be hidden from the Screen Options. This code works with HPOS storage, enabled by default on recent shops, as well as with the old storage:

add_filter( 'manage_woocommerce_page_wc-orders_columns', 'wycan_colonne_societe' );
add_filter( 'manage_edit-shop_order_columns', 'wycan_colonne_societe' );
function wycan_colonne_societe( $columns ) {
    $nouvelles = array();
    foreach ( $columns as $cle => $libelle ) {
        $nouvelles[ $cle ] = $libelle;
        if ( 'order_status' === $cle ) {
            $nouvelles['billing_company'] = 'Company';
        }
    }
    return $nouvelles;
}

add_action( 'manage_woocommerce_page_wc-orders_custom_column', 'wycan_colonne_societe_contenu', 10, 2 );
add_action( 'manage_shop_order_posts_custom_column', 'wycan_colonne_societe_contenu', 10, 2 );
function wycan_colonne_societe_contenu( $column, $commande ) {
    if ( 'billing_company' !== $column ) {
        return;
    }
    $commande = $commande instanceof WC_Order ? $commande : wc_get_order( $commande );
    if ( $commande ) {
        echo esc_html( $commande->get_billing_company() );
    }
}

Hide payment methods from pros

For example, do not offer PayPal or check to pro accounts:

add_filter( 'woocommerce_available_payment_gateways', 'wycan_paiements_pro' );
function wycan_paiements_pro( $passerelles ) {
    if ( ! in_array( 'pro', (array) wp_get_current_user()->roles, true ) ) {
        return $passerelles;
    }

    foreach ( array( 'check', 'paypal' ) as $id ) {
        unset( $passerelles[ $id ] );
    }

    return $passerelles;
}

You can read the payment method IDs in the address of their settings page, under WooCommerce, Settings, Payments.

What next?

With these building blocks, your shop welcomes businesses with their own prices and their own rules, without building a second site. For a true B2B portal (prices negotiated per customer, recurring orders, a link to your ERP), custom development often becomes easier to maintain than a stack of plugins.

Have a B2B project on WooCommerce? We build the rules that fit the way you sell, or let’s talk about your shop.

Contents
Read next

More articles that may help you

Illustration au trait : un casque audio, une onde sonore, un stockage de fichiers et le symbole d’un flux RSS

Self-hosted podcast: moving a podcast to WordPress and Cloudflare R2

Read the article →
Illustration au trait : une patinoire vue de dessus, des sapins et un écran d’état avec deux pastilles

Ice rink and skating trail: a municipality’s custom WordPress plugin

Read the article →
WooCommerce e-invoicing: how to make your shop compliant

WooCommerce e-invoicing: how to bring your shop into compliance

Read the article →

A project, a question?

Free quote · Refundable deposit · Balance only if satisfied · No commitment