Customizing WooCommerce Order Numbers With Prefix And Year Suffix | Code For Developers

Customizing WooCommerce Order Numbers with Prefix and Year Suffix

Customize WooCommerce order numbers your way, whether you prefer code or a plugin. Add unique prefixes and dynamic year-based suffixes effortlessly. Make your store’s orders truly yours!

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.

Previous Code

How to Implement Google Ads Conversion Tracking in WooCommerce

Learn how to add Google Ads tracking code to your ...

Next Code

Sequential Fading jQuery Text Animation

This code animates text using jQuery, creating a s ...

Leave a Reply

Your email address will not be published. Required fields are marked *

If you find it useful

Buy me a coffee









Update WooCommerce Delivery cost with condition

Change Delivery price base on what item in cart ...

Implementing WooCommerce Shop Page Quantity Input and Plus (+) Minus (-) Button with simple Code

Enhance the user experience on your WooCommerce we ...

Add an additional custom checkbox in the WooCommerce checkout

Add an additional custom checkbox after the terms ...

WooCommerce Ajax Product Search and Category Filter Without Plugin

WooCommerce Ajax Product Search with Category Filt ...

WooCommerce Discount based on Cart Item

A discount on the total order with condition based ...