December 30, 2024
2 min read

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.

functions.php
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.

Leave a Reply

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

WooCommerce Mostly used Shortcode

Most use shortcode for popular eCommerce plugin WooCommerce.

Update WooCommerce Delivery cost with condition

Change Delivery price base on what item in cart

Get WooCommerce product info

Show product info in the place as you wish to. It help you to make your custom woocommerce product page layout.

Sticky Menu Show when scrolling up

Header bar only show when scrolling up with simple jQuery and CSS trick.

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.