Discussions

Custom order number or ID?

Hi... I am completely new to Drupal Commerce and, on top of that, a web designer with very little development knowledge.

My client wishes to have their invoice numbers display the date before the number...

ex: 20140709-1

However, I can not figure out how to do this.

I've been Googling for hours. I have been finding a lot of people asking this question, but most of the requests for help either have no responses or a bunch of responses from people looking for the same thing.

I figured this was something which could be done through a checkout rule, but I have not been able to figure out how to get it to work.

I have tried installing the Commerce Order Counter module, but can't seem to get it to work. I have also tried various hooks I have found, but I am either doing the whole hook thing incorrectly or they simply are not doing what I need them to.

Does anyone have any experience on doing this and, if yes, can you point me in a direction which will work? It would be very much appreciated.

Thanks!

Posted: Jul 9, 2014

Comments

rOprOprOp on January 11, 2016

just add something like this in a custom module.

/**
* Implements hook_commerce_order_presave().
*/
function MYMODULE_commerce_order_presave($order) {
  if (isset($order->order_id)) {
    $order->order_number = date('ydm') . "-". $order->order_id;
  }
}