[Drupal] How to add custom values to ubercart order?

| | 1 min read

We had a requirement in one of our E-commerce site built using Ubercart module to add a custom key while saving an ubercart order, the key had to be used later on based on which the status of order is changed. Read on to know more.

We altered the review form using hook_form_FORM_ID_alter() to add a custom submit handler while saving the order. The following code added to submit handler will help to save the custom value in ubercart order.

    function custom_submit_uc_order(&$form, &$form_state) {
       $status = custom_get_status();
       $order = uc_order_load($_SESSION['cart_order']);
       $order->data['custom']['status'] = $status;

Hope this helps.