1. Home
  2. Knowledge Base
  3. WooCommerce Wholesale Prices Premium
  4. Backend
  5. How To Add A Custom Prefix Order Number For Wholesale Orders

How To Add A Custom Prefix Order Number For Wholesale Orders

If you want wholesale orders to stand out at a glance, you can give them their own order number prefix. For example, you can turn order #1234 into WH-1234. This article shows you how to add a custom prefix to wholesale order numbers with a code snippet. That makes it easy to tell wholesale and retail orders apart in the WooCommerce orders list.

Prerequisites

  • WooCommerce Wholesale Prices Premium must be installed and active. The order type detection used in this snippet relies on the _wwpp_order_type meta key, which is set by this plugin at checkout.
  • Access to add custom PHP code, either via your active child theme’s functions.php file or a code snippet plugin such as WPCode.

The order type column

When a wholesale order is placed, WooCommerce Wholesale Prices Premium adds an Order Type column to the WooCommerce Orders page so you can see at a glance which orders came from wholesale customers.

Order Type column in the WooCommerce Orders list

You can take this further by adding a custom prefix to the order number for wholesale orders. Add the following snippet to your child theme’s functions.php or a code snippet plugin:

add_filter( 'woocommerce_order_number', 'wwpp_custom_wholesale_order_number_prefix', 10, 2 );
function wwpp_custom_wholesale_order_number_prefix( $order_number, $order ) {

    $prefix     = 'WH-'; // Change this to any prefix you like
    $order_type = $order->get_meta( '_wwpp_order_type', true ); // HPOS-compatible meta read

    if ( 'wholesale' === $order_type ) {
        return $prefix . $order_number;
    }

    return $order_number;
}

Change the value of $prefix to any string you like, for example 'WHSL-' or 'B2B-'. The prefix is prepended to the existing order number, so order #1234 becomes WH-1234.

This snippet uses $order->get_meta() to read the order type. This is the correct approach for sites using WooCommerce’s High-Performance Order Storage (HPOS). Using get_post_meta() directly will not work on HPOS-enabled stores because order data is no longer stored in the posts table.

Result

Here’s the result:

Custom prefix applied to the wholesale order number

Troubleshooting

The prefix is not appearing on wholesale orders. Confirm that WooCommerce Wholesale Prices Premium is active. The _wwpp_order_type meta is set by this plugin at checkout, so orders placed before it was installed will not have the meta and will not match. Also check that the snippet was added to your child theme’s functions.php (not the parent theme file, which will be overwritten on theme updates) or a code snippet plugin.

The prefix appears on all orders, not just wholesale ones. Check that the $order->get_meta( '_wwpp_order_type', true ) call is returning 'wholesale' for the expected orders. You can temporarily add a var_dump call inside the function (on a development site only) to inspect the return value.

Need Help?

If you have a question or run into any issues, we’re here to help.

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support
Complete Your Purchase