1

I'm using Drupal Commerce 7.x. I have added some fields to the checkout form in the customer profile. Specifically I've added 'Title' and 'Organization'. I'd like to move some of the fields around because they aren't in the order I'd like, but I can't figure out how to move them.

For example, right now the order is: 1. Country (I def. don't want that first) 2. Full name 3. Address etc.

I want it like this:

  1. Full Name
  2. Title (new field)
  3. Organization (new field)

I tried using a module that does this (just as an example, obviously, since only two fields are listed here). Am I on the right track?

<?php
function CommerceAlter_form_commerce_checkout_form_alter(&$form, 
&$form_state, &$form_id) {
   $order = array('edit-customer-profile-billing-field-title', 
'addressfield-container-inline');
    foreach ($order as $key => $value){
      if (isset($form[$value])){
        $form[$value]['#weight'] = $key;
      }
    }
}

But it didn't do anything.

Note: I was unsure how to reference the fields. The first one above called 'field-title' is the ID for that field and the second listed for addressfield (which is in the form by default) is by class .addressfield-container-inline).

2

Changing field order on the checkout form can be done by going to admin/commerce/config/checkout

Then just drag the items up and down to arrange them in the order you wish.

  • except that some of the fields I want to re-order are included in the 'Address' field. If you go to admin > store > customer profiles > profile types > billing information you'll see what I mean. It just says 'Address'. But that includes a bunch of fields and I don't know how they are part of the Address field but it includes name, city, state, etc. and I want to re-order those with my new fields I've added. – Sage Sep 11 '15 at 4:15
  • 2
    The Address field is from the Address field module which drupal commerce includes. You control everything through views. In views you can remove the default address grouping and add in individual address fields in any order you like. The view is Customer Profiles. – Craig Bowman Sep 11 '15 at 7:05
  • @CraigBowman nice explanation, thanks - but 4 years later i dont have a "Customer Profiles" view. and i have the same problem, we need to split up the address form parts for example. – netzding Nov 14 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.