Wholesale Bulk Order Form

Introduction #

B2BKing introduces a powerful wholesale bulk order form that allows your B2B customers to place orders quickly and easily. Customers can search for products by name or SKU, save purchase lists for later use, or simply browse and discover your catalog.

The form is added by default to B2B customers' WooCommerce "My Account" page and can also be added to any page using shortcodes.

Wholesale Bulk Order Form in the My Account section of WooCommerce

The bulk order form is powered by a fast AJAX search, allowing customers to easily search for and discover products.

Order Form Themes #

You can choose from three different order form themes: Classic, Indigo, and Cream.

Classic theme:

Indigo theme:

Cream theme:

Learn more: Here you can learn about the available themes and display options.

Bulk Order Form Shortcode #

To add the form to any page, you can use the shortcode [b2bking_bulkorder].

Theme Parameter #

To select a specific theme, you can use the theme parameter:

[b2bking_bulkorder theme=indigo]

[b2bking_bulkorder theme=cream]

[b2bking_bulkorder theme=classic]

Exclude Products, Categories, or Tags #

You can exclude specific items by using the exclude parameter (this is only available for the Cream and Indigo themes).

[b2bking_bulkorder theme=cream exclude=432,983]

The exclude parameter also supports categories by entering them as 'category_123', where 123 is the category ID. For example, [b2bking_bulkorder theme=cream exclude=12,category_34] will exclude the product with ID 12 and all products that belong to the category with ID 34. You can also exclude tags in the same way, e.g.: [b2bking_bulkorder theme=cream exclude=tag_54,tag_877]

Show Specific Products or Categories #

You can choose a specific category by specifying its ID:

[b2bking_bulkorder theme=cream category=123]

This will make the shortcode only show products from the category with ID 123.

You can also select multiple categories by separating them with a comma:

[b2bking_bulkorder theme=cream category=123,332]

If you want to show only a specific list of products (only those products and nothing else), you can use:

[b2bking_bulkorder theme=cream product_list="49, 188"]

Here, 49 and 188 are examples of product IDs. The above shortcode will limit the list to these 2 products.

Show Specific Tags #

You can choose a specific tag by specifying either its slug/name or its ID. Examples:

[b2bking_bulkorder theme=cream tag="blue, red, cream"]

[b2bking_bulkorder theme=cream tag="123, 567"]

[b2bking_bulkorder theme=cream tag=new]

Sort Products By #

Another parameter you can use is the sortby parameter, which controls how items are sorted by default. The three available options are: atoz, ztoa, and bestselling. The first two sort alphabetically from A to Z or from Z to A, while the last one puts the best-selling items first.

[b2bking_bulkorder theme=cream sortby=bestselling]

Add SKU or Stock Columns #

The Cream theme supports showing SKU and Stock Quantity columns:

To enable this, use sku=yes and/or stock=yes in your shortcode, e.g.:

[b2bking_bulkorder theme=cream sku=yes]

[b2bking_bulkorder theme=cream stock=yes]

[b2bking_bulkorder theme=cream sku=yes stock=yes]

Filter by Attributes #

You can also add a filter-by-attributes selector, for example to filter by color or size:

You can set the attributes and the button text in the shortcode:

[b2bking_bulkorder theme=cream attributes="color,size" attributestext="Color / Size"]


attributes = 
a comma-separated list of attribute slugs you want to include in the shortcode

attributestext = the actual text of the button. It defaults to "Attributes", but you can set custom text.

Multiselect #

Multiselect allows customers to select and add multiple items to the cart at once with a single click. This can be enabled globally in the B2BKing order form settings, but it can also be controlled in each shortcode individually.

Examples:

[b2bking_bulkorder theme=cream multiselect=yes]

[b2bking_bulkorder theme=cream multiselect=no]

Multiselect Enabled

Edit Shortcode on the My Account Page #

The My Account page uses the default [b2bking_bulkorder] shortcode without any parameters. You may want to set certain parameters in order to choose specific categories, products, etc.

To do this, you can use the following code snippet:

add_filter('b2bking_my_account_bulkorder_shortcode', function($val){
	$shortcode = '[b2bking_bulkorder]';
	return $shortcode;
}, 10, 1);

You can modify the shortcode within the above snippet.

This code snippet can be added to functions.php or by using any snippets plugin.

Add a Custom Column to the Cream Order Form #

You may want to add a custom column when using the plugin's Cream order form. This is possible with code snippets. Let's look at a few examples:

Add a Price Column #

You can do this by adding the following PHP code snippet to your site:

add_action('b2bking_bulkorder_cream_custom_heading', function(){
	?>
	<div class="b2bking_bulkorder_form_container_content_header_cream_sku">
		<?php esc_html_e('Price', 'b2bking'); ?>
	</div>
	<?php
});
add_action('b2bking_bulkorder_cream_custom_column', function($product){
	?>
	<div class="b2bking_bulkorder_cream_sku"><?php 

	$sale_price = $product->get_sale_price();
	$sale_price = round(floatval(b2bking()->b2bking_wc_get_price_to_display( $product, array( 'price' => $sale_price))),2);
	$regular_price = $product->get_regular_price();
	$regular_price = round(floatval(b2bking()->b2bking_wc_get_price_to_display( $product, array( 'price' => $regular_price))),2);

	if ($product->is_on_sale()){
		$price_display = wc_format_sale_price($regular_price, $sale_price);
	} else {
		$price_display = wc_price($regular_price);
	}

	echo $price_display;
	
	?></div>
	<?php
}, 10, 1);

This specifically adds a Price column that can also display discounts:

Add an Attribute Column (e.g. Brand, Color) #

To add a column for an attribute such as "Material", you can use this code:

add_action('b2bking_bulkorder_cream_custom_heading', function(){
	?>
	<div class="b2bking_bulkorder_form_container_content_header_cream_sku">
		<?php esc_html_e('Material', 'b2bking'); ?>
	</div>
	<?php
});
add_action('b2bking_bulkorder_cream_custom_column', function($product){
	?>
	<div class="b2bking_bulkorder_cream_sku"><?php 

	echo $product->get_attribute('pa_material');
	
	?></div>
	<?php
}, 10, 1);

This results in a column showing that attribute for each product:

Input Field That Saves to the Order #

The customer types something into the field (e.g. a color code or note), and it gets saved to the cart item and the order. Use the CSS class customdata_{product_id} on the input. B2BKing automatically collects fields with this class and includes their values when the product is added to the cart.

/* Step 1 — Add the input field */

add_action('b2bking_bulkorder_cream_custom_heading', function() {
    ?>
    <div class="b2bking_bulkorder_form_container_content_header_cream_sku">
        <?php esc_html_e('Color Code', 'b2bking'); ?>
    </div>
    <?php
});

add_action('b2bking_bulkorder_cream_custom_column', function($product) {
    ?>
    <div class="b2bking_bulkorder_cream_sku">
        <input type="text"
               class="customdata_<?php echo esc_attr($product->get_id()); ?>"
               placeholder="e.g. RAL 9010">
    </div>
    <?php
}, 10, 1);

/* Step 2 — Capture the value and save it to the cart item */

add_filter('b2bking_skip_get_product_add_cart', '__return_true');

add_filter('b2bking_bulkorder_add_cart_item_data', function($data, $product_id, $qty, $product) {
    if (!empty($_POST['customdata'][0])) {
        $data['color_code'] = sanitize_text_field($_POST['customdata'][0]);
    }
    return $data;
}, 10, 4);

/* Step 3 — Display the value in the cart and checkout */

add_filter('woocommerce_get_item_data', function($cart_data, $cart_item) {
    if (!empty($cart_item['color_code'])) {
        $cart_data[] = array(
            'name'    => __('Color Code', 'b2bking'),
            'display' => $cart_item['color_code'],
        );
    }
    return $cart_data;
}, 10, 2);


/* Step 4 — Save the value to the order */

add_action('woocommerce_checkout_create_order_line_item', function($item, $cart_item_key, $values, $order) {
    if (!empty($values['color_code'])) {
        $item->add_meta_data(__('Color Code', 'b2bking'), $values['color_code']);
    }
}, 10, 4);

This will display a custom column with an input field:

The text entered in this input will be passed to the cart and order:

Group Products by Brand (or Taxonomy) #

Sometimes you may want to display products in a specific order or group them in a particular way on your order form. B2BKing is flexible enough to handle a variety of custom sorting and grouping scenarios.

For example, let's say you want to group products by brand, and within each brand, list the products alphabetically. This approach works best when your catalog is small enough that all products fit comfortably on a single page. If you need to adjust how many items are displayed per page, refer to the snippets further down in this article.

Here's what this looks like in practice:

Sort Products by Brand / Custom Sorts #

To implement the sort by brand or any other custom sorts, you can use the hook 'b2bking_orderform_product_ids_before_processing'. Here is the full sort by brand code snippet:

add_filter('b2bking_orderform_product_ids_before_processing', function($allTheIDs) {
    if (empty($allTheIDs) || !is_array($allTheIDs)) {
        return $allTheIDs;
    }

    // Change 'product_brand' to your actual brand/category taxonomy slug if you are using a brands plugin rather than default WooCommerce brands.
    $taxonomy = 'product_brand';

    $products_data = [];

    foreach ($allTheIDs as $product_id) {
        $terms = get_the_terms($product_id, $taxonomy);
        $brand_name = (!empty($terms) && !is_wp_error($terms))
            ? strtolower($terms[0]->name)
            : 'zzz_uncategorized'; // push brandless products to the end

        $product_title = strtolower(get_the_title($product_id));

        $products_data[] = [
            'id'    => $product_id,
            'brand' => $brand_name,
            'title' => $product_title,
        ];
    }

    // Sort by brand alphabetically, then by product title within each brand
    usort($products_data, function($a, $b) {
        $brand_cmp = strcmp($a['brand'], $b['brand']);
        if ($brand_cmp !== 0) {
            return $brand_cmp;
        }
        return strcmp($a['title'], $b['title']);
    });

    return array_column($products_data, 'id');
});

Show a Brand Header Row Between Groups #

Once the list is sorted, it can still feel a bit disorganized without visual separators indicating each group. To solve this, you can add custom header rows that appear above each brand section. The following snippet inserts a header row whenever the brand changes:

add_action('b2bking_before_orderform_cream_product', function($product_id) {
    static $last_brand = null;

    $taxonomy = 'product_brand';
    $terms = get_the_terms($product_id, $taxonomy);
    $brand_name = (!empty($terms) && !is_wp_error($terms)) ? $terms[0]->name : 'Other';

    if ($brand_name !== $last_brand) {
        $last_brand = $brand_name;
        echo '<div class="b2bking_brand_header_row">'
            . esc_html($brand_name)
            . '</div>';
    }
});

The headers can be styled with some custom CSS. The below example adds a simple, clean, spaced out header row:

.b2bking_brand_header_row{
	width:100%; 
	padding: 8px 12px; 
	font-weight:bold; 
	margin: 30px 0px;
}

Code Snippets #

Show Out of Stock Products in the Order Form #

By default, the plugin only shows products that are purchasable (in stock, have a price, etc.).

It is also possible to show out-of-stock items in the order form. To do so, add the following PHP code snippet to your site:

add_filter('b2bking_allow_outofstock_order_form','__return_true');

To allow showing all products that are not purchasable, you can add the following snippet instead:

add_filter('b2bking_allow_all_orderform', '__return_true');

Adjust the Number of Products Per Page #

By default, the Cream and Indigo order forms display up to 100 products per page. You can change this value using the snippet below:

add_filter('b2bking_search_results_number_order_form', function($results){ 
	return 100;
}, 10, 1);

Keep in mind that the number you set is approximate. Because additional filters and checks are applied after the initial query, the actual number of displayed products may end up slightly lower, for example 87 or 93 instead of 100.

Hide Product Sorting Filters #

To remove sorting from the filters sidebar, use the following snippet:

add_filter('b2bking_bulkorder_skip_sort', '__return_true');

Hide the Filters Area Entirely #

To hide filters, you can use the following custom CSS:

.b2bking_orderform_filters {
	display: none !important;
}
.b2bking_bulkorder_form_container_content_header_top.b2bking_bulkorder_form_container_content_header_top_cream.b2bking_orderform_cart {
	width: 13%;
}
.b2bking_bulkorder_form_container_content_header_top.b2bking_bulkorder_form_container_content_header_top_cream:not(.b2bking_orderform_cart) {
	width: 87%;
	flex-direction: row-reverse;
}
.b2bking_bulkorder_cream_search_icon.b2bking_bulkorder_cream_search_icon_show.b2bking_bulkorder_cream_search_icon_search {
	margin-right: 17px;
}

Performance Optimizations #

To optimize and improve order form performance, please see the dedicated 'Bulk Order Form' section in our performance optimization article.

Powered by BetterDocs