Index: .
===================================================================
--- .	(revision 114)
+++ .	(working copy)
@@ -2,6 +2,34 @@
 // $Id: uc_order.order_pane.inc,v 1.1.2.19 2009/09/23 19:50:45 islandusurper Exp $
 
 /**
+ * A callback function used to sort the fields according to their weight.
+ */
+function _uc_order_pane_weight_sort( $fieldA, $fieldB ) {
+   if( !($fieldA['#weight'] && $fieldB['#weight']) || ($fieldA['#weight'] == $fieldB['#weight']) ) {
+      return 0;
+   }
+   return ($fieldA['#weight'] < $fieldB['#weight']) ? -1 : 1;
+}
+
+/**
+ * A function used to return a sorted array of fields ( based on weight ).
+ */
+function _uc_order_pane_get_fields( $fields ) {
+   $sorted = array();
+      
+   // Add the fields to the fields array.
+   foreach( element_children($fields) as $field ) {
+      $sorted[$field] = $fields[$field];
+   }
+      
+   // Now sort the fields based on weight.
+   usort( $sorted, "_uc_order_pane_weight_sort" ); 
+
+   // Return the sorted fields.
+   return $sorted;
+}
+
+/**
  * @file
  * This file contains the callbacks for the default order panes supplied with
  * Ubercart and their corresponding helper functions.
@@ -78,11 +106,11 @@
 
     case 'edit-theme':
       $output = '<div id="delivery_address_select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['ship_to']) as $field) {
-        $title = $arg1['ship_to'][$field]['#title'];
-        $arg1['ship_to'][$field]['#title'] = NULL;
+      foreach (_uc_order_pane_get_fields($arg1['ship_to']) as $field) {
+        $title = $field['#title'];
+        $field['#title'] = NULL;
         $output .= '<tr><td class="oet-label">'. $title .':</td><td>'
-                 . drupal_render($arg1['ship_to'][$field]) .'</td></tr>';
+                 . drupal_render($field) .'</td></tr>';
       }
       $output .= '</table>';
       return $output;
@@ -167,11 +195,11 @@
 
     case 'edit-theme':
       $output = '<div id="billing_address_select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['bill_to']) as $field) {
-        $title = $arg1['bill_to'][$field]['#title'];
-        $arg1['bill_to'][$field]['#title'] = NULL;
+      foreach (_uc_order_pane_get_fields($arg1['bill_to']) as $field) {
+        $title = $field['#title'];
+        $field['#title'] = NULL;
         $output .= '<tr><td class="oet-label">'. $title .':</td><td>'
-                 . drupal_render($arg1['bill_to'][$field]) .'</td></tr>';
+                 . drupal_render($field) .'</td></tr>';
       }
       $output .= '</table>';
       return $output;
@@ -245,11 +273,11 @@
 
     case 'edit-theme':
       $output = '<div id="customer-select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['customer']['text']) as $field) {
-        $title = $arg1['customer']['text'][$field]['#title'];
-        $arg1['customer']['text'][$field]['#title'] = NULL;
+      foreach (_uc_order_pane_get_fields($arg1['customer']['text']) as $field) {
+        $title = $field['#title'];
+        $field['#title'] = NULL;
         $output .= '<tr><td class="oet-label">'. $title .':</td><td>'
-                 . drupal_render($arg1['customer']['text'][$field]) .'</td></tr>';
+                 . drupal_render($field) .'</td></tr>';
       }
       $output .= '</table>'. drupal_render($arg1['customer']['primary_email'])
                . drupal_render($arg1['customer']['uid']);
