Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce for Wordpress: How to modify the order number/id?

I have implemented WooCommerce to my webshop and have connected a CorvusPay gateway for online payment.

Now the problem that we are having is that Corvus requires my order numbers to contain characters (uppercase and lowercase) along with numbers.

I have seen and tried many plugins and filters on how to change my order numbers inside Wordpress, but whilst the order is being processed and sent to Corvus the number is still the same old post ID.

I am aware that WooCommerce uses Wordpress post IDs to create the initial order numbers, but how can I change this?

How can I modify WooCommerce so that it uses a specific method of order number generation, that is I'd like the order numbers to be e.g. "Kr-12345" and not "12345".

I need a way to change its method of number generation and not use a plugin like Sequential Order Numbers since that just changes the numbers in my Wordpress page.

like image 534
Kalipto Avatar asked Dec 03 '25 23:12

Kalipto


1 Answers

You can use the woocommerce_order_number hook to filter the value however you want. This guide explains how to use it for simply adding a prefix and suffix.

add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );

function change_woocommerce_order_number( $order_id ) {
    $prefix = 'VK/';
    $suffix = '/TS';
    $new_order_id = $prefix . $order_id . $suffix;
    return $new_order_id;
}

So it looks like this would do what you're wanting. You could just remove the suffix if you don't need it, or make any necessary adjustments to the format of $new_order_id.

Another thing to keep in mind is that if you're using a plugin like PayPal for WooCommerce it has an option to set an invoice prefix built in.

like image 152
Drew Angell Avatar answered Dec 05 '25 12:12

Drew Angell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!