Advertisement
daymobrew

Woocommerce - Change order of checkout fields

Oct 16th, 2015
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. // Change order of billing fields on checkout page.
  2. // From: http://wordpress.stackexchange.com/a/78377
  3. add_filter('woocommerce_checkout_fields', 'bdd_reorder_billing_fields', 15);
  4. function bdd_reorder_billing_fields($fields) {
  5.     $order = array(
  6.         'billing_first_name',
  7.         'billing_last_name',
  8.         //'billing_company',
  9.         'billing_address_1',
  10.         'billing_email',
  11.         'billing_address_2',
  12.         'billing_phone',
  13.         'billing_city',
  14.         'billing_state',
  15.         'billing_country',
  16.         'billing_postcode',
  17.     );
  18.     foreach($order as $field)
  19.     {
  20. // TODO: Check that $field is in $fields before saving it.
  21.         $ordered_fields[$field] = $fields['billing'][$field];
  22.     }
  23.  
  24.     $fields['billing'] = $ordered_fields;
  25.    
  26.     $fields['billing']['billing_first_name']['class'] = array('form-row-first');
  27.     $fields['billing']['billing_last_name']['class'] = array('form-row-last');
  28.     $fields['billing']['billing_address_1']['class'] = array('form-row-first', 'address-field');
  29.     $fields['billing']['billing_email']['class'] = array('form-row-last');
  30.     $fields['billing']['billing_address_2']['class'] = array('form-row-first', 'address-field');
  31.     $fields['billing']['billing_phone']['class'] = array('form-row-last');
  32.     $fields['billing']['billing_city']['class'] = array('form-row-first', 'address-field');
  33.     $fields['billing']['billing_state']['class'] = array('form-row-first', 'address-field');
  34.     $fields['billing']['billing_country']['class'] = array('form-row-first');
  35.     $fields['billing']['billing_postcode']['class'] = array('form-row-first', 'address-field');
  36.  
  37. //echo '<!-- FIELDS: '.var_export($fields, true). ' -->';
  38.  
  39.     return $fields;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement