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 *

WordPress Ajax Search without plugin [ Easy ]

WordPress Ajax Search without plugin. Fully custom code work with woocommerce as well

WordPress category or taxonomy list

WordPress custom taxonomy term list with function and loop. show taxonomy team on wp query loop

Jquery Replace specific text in all element

Scenario Imagine you have a set of elements with the class specific_class, and they all contain the phrase “old text.” You want to replace this phrase with “New text” programmatically. The Solution Here’s a simple jQuery script to achieve this: How It Works Things to Keep in Mind Extending the Script jQuery provides a quick […]

JS set interval for an event until element show

Sometimes we need to active an event when a specific element loads on-page or part of an element change.

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.