Have you ever wanted to add a unique touch to your WooCommerce order numbers? With a simple code snippet or an easy-to-use plugin, you can customize your order numbers by adding a custom prefix and a dynamic year-based suffix.
Step 1: Adding a Custom Prefix
In this code snippet, we begin by defining a custom prefix. You can replace 'yourprefix'
it with any text you desire. This prefix will be added to all your order numbers, giving them a distinct identifier.
add_filter('woocommerce_order_number', 'change_woocommerce_order_number', 1, 2);
function change_woocommerce_order_number($order_id, $order) {
$prefix = 'yourprefix';
$suffix = '-' . date('Y');
return $prefix . $order->id . $suffix;
}
Step 2: Dynamic Year-Based Suffix
The code also includes a dynamic year-based suffix. This means that the year will automatically update without manual intervention. For example, if the current year is 2023, your order numbers will have a suffix like -2023
.
How It Works
The code snippet utilizes the WooCommerce filter woocommerce_order_number
. When an order is created, this filter is applied, and the custom function change_woocommerce_order_number
is triggered.
Inside the function, the prefix, order ID, and year suffix are combined to create the modified order number. The result is a unique order number format like 'yourprefix12345-2023'
, where 12345
represents the order ID and 2023
is the current year.
Get Creative
Feel free to get creative with your custom prefix and adapt the code to your specific needs. Whether you’re looking to add branding, date-based identifiers, or any other unique touch, this code snippet offers a simple way to make your WooCommerce order numbers your own.
Or Use Our Plugin
If you prefer a hassle-free solution without writing code, you can check out our WC Order Numbers Prefix & Suffix plugin on GitHub. Simply download and install the plugin, and you’ll have an easy-to-use interface for customizing your order numbers.
Customizing your order numbers not only adds a personal touch but also helps with organization and tracking. Give it a try and make your WooCommerce store even more distinctive!
That’s it! With just a few lines of code or a convenient plugin, you can easily customize your WooCommerce order numbers and make them stand out.