Reputation: 31
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.
Upvotes: 3
Views: 21794
Reputation: 1326
This looks like another case of the developer of the gateway not implementing the gateway correctly. For my answer I am assuming that you are using CorvusPay WooCommerce Integration.
If you at the process_payment()
function in classes.php you'll see that the plug-in always sends the actual post_id for the order to the gateway every time:
/**
* This method accepts payment request initiated by user, and redirects
* him to CorvusPay IPG.
* @param int $order_id
* @return array
*/
public function process_payment($order_id) {
// Load options
$options = $this->_getOptions();
$checkout_page_id = $options[CpsiKeys::OPTION_CHECKOUT_PAGE_ID];
return array(
'result' => 'success',
'redirect' => add_query_arg('order_id', $order_id, get_permalink($checkout_page_id))
);
}
This means no matter what trick you try, you will not be able to overcome the issue without this function getting modified because the plugin always sends the wrong piece of information (or at-least in the wrong format).
There are a number of fixes for this:
-
/**
* This method accepts payment request initiated by user, and redirects
* him to CorvusPay IPG.
* @param int $order_id
* @return array
*/
public function process_payment($order_id) {
// Load options
$options = $this->_getOptions();
$checkout_page_id = $options[CpsiKeys::OPTION_CHECKOUT_PAGE_ID];
return array(
'result' => 'success',
'redirect' => add_query_arg('order_id', 'ABx' . $order_id, get_permalink($checkout_page_id))
);
}
Where ABx
is your prefix.
Koda
Upvotes: 0
Reputation: 26036
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.
Upvotes: 5