How to Add a Prefix/Suffix to B2B / B2C Order Numbers or Split B2B / B2C Orders

Change Order Number #

You may want to differentiate between B2B and B2C orders via order number if you are running a hybrid site. Here is a simple code snippet that can do it.

// Add Prefix to Orders by B2B
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );

function change_woocommerce_order_number( $order_id ) {
	// get if customer is B2B
	$order = wc_get_order($order_id);
	$customer_id = $order->get_customer_id();
	$customer_b2b = get_user_meta($customer_id,'b2bking_b2buser', true);
	if ($customer_b2b === 'yes'){
	    $prefix = 'PRO-';
            $suffix = '';
	    $order_id = $prefix . $order_id . $suffix;
	return $order_id;

This code adds "PRO-" to all orders of B2B customers.

Here's what that looks like in practice in the backend.

This is a simple way to differentiate between orders and it can be useful in many scenarios, especially for delivery and order fulfillment.

Split B2B and B2C Orders in Admin #

You can also split orders and achieve the following display:

B2B Orders are highlighted in the right column

To achieve this display, please add the following code snippet to the admin side of the store.

// Split orders if plugin is used in Hybrid Mode
if(get_option( 'b2bking_plugin_status_setting', 'disabled' ) === 'hybrid'){
	function tk_add_new_order_admin_list_column( $columns ) {
	    $columns['check_is_b2b_order'] = '<p style="text-align:right;">B2B</p>';
	    return $columns;
	add_filter( 'manage_edit-shop_order_columns', 'tk_add_new_order_admin_list_column', 10, 1 );

	function tk_add_new_order_admin_list_column_content( $column ) {
	    global $woocommerce, $post;
	    if ( 'check_is_b2b_order' === $column ) {
	        $order = wc_get_order( $post->ID );
	        $customer_id = $order->get_customer_id();
	        $customer_b2b = get_user_meta($customer_id,'b2bking_b2buser', true);

	        if ($customer_b2b === 'yes'){
	            echo '<p style="text-align:right;"><span class="dashicons dashicons-yes-alt"></span></p>';


	add_action( 'manage_shop_order_posts_custom_column', 'tk_add_new_order_admin_list_column_content', 10, 1 );

Powered by BetterDocs