13 replies [Last post]
Guest
Guest's picture
Was this information Helpful?

I see that the address fields can be renamed on the following page:
Store administration > Configuration > Checkout settings > Address fields

Is it possible to change the weight of these fields? The Zone is appearing below the Country, which is unusual for the UK address format.

Thanks
Greg

mikejoconnor's picture
Offline
AdministratorBug FinderGetting busy with the Ubercode.
Joined: 08/07/2007
Juice: 536
Re: Order of address fields

If nothing else you should be able to use hook_form_alter($form_id, &$form) to adjust this.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Order of address fields

Yeah, you'll have to use Mike's suggestion for now. Had I known more at the time, I would've gone for totally flexible checkout fields, but the only way to order them at the moment would be through that hook.

Having the country first is weird for us, too, but for stores that sell to multiple countries it was necessary to have the country first so the zone box could be updated to that particular country's zones.

Forbid's picture
Offline
Joined: 02/10/2009
Juice: 44
Re: Re: Re: Order of address fields

Sorry to necro such an old thread, but I don't believe there is any kind of support for this still a year and a half later. I know that this makes sense for some countries, but the majority of our customers are going to be US and I'd rather just put some kind of message that tells people that need to choose country first to do so then have it be that way for everyone. It's very unintuitive since people tab through the fields as they fill them out, or at least I do, and they're use to things being in a certain order since every other site I've ever ordered from lists city, state, zip, country. Is there any way around this or plans to incorporate being able to change the order?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Order of address fields

I don't believe there's any simple way around it right now other than simply re-theming that part of the checkout form. I'm not proud of that code, though, so I can't promise it will be an enriching experience. Eye-wink

wayaslij's picture
Offline
Joined: 11/27/2009
Juice: 6
A solution - drupal 6

I had the same issues and this is how I solved it. I wanted the postal code field to appear before the city field.
I'm sure the php code can be optimized, and I would be glad to see another version.

<?php
/**
* Implementation of hook_form_alter().
*/
function MODULENAME_form_alter(&$form, $form_state, $form_id) {
    switch (
$form_id) {
        case
'uc_cart_checkout_form':
           
/**
             * Change checkout address fields order.
             */
           
$n = 0;
           
// Browse all array to find the elements positions.
           
foreach ($form['panes']['billing'] as $key => $elem) {
                if (
$key == 'billing_city') $city_pos = $n;
                if (
$key == 'billing_postal_code') $postal_code_pos = $n;
               
$n++;
            }
           
// Extract the postal_code element.
           
$postal_code_array = array_splice($form['panes']['billing'], $postal_code_pos, 1);
           
// Split $form into two parts.
           
$form_end = array_splice($form['panes']['billing'], $city_pos);
           
// Inser back the postal.
           
$form['panes']['billing'] = array_merge($form['panes']['billing'], $postal_code_array, $form_end);
            break;
  }
?>
TheoRichel's picture
Offline
Joined: 09/02/2010
Juice: 48
Wayaslii or Ryan or someone else

As I am fairly new to Ubercart: do you have any instructions as to where and how I should paste this code?

Many thanks

Theo Richel

TheoRichel's picture
Offline
Joined: 09/02/2010
Juice: 48
Wayaslii or Ryan or someone else

As I am fairly new to Ubercart: do you have any instructions as to where and how I should paste this code?

Many thanks

Theo Richel

tammo's picture
Offline
Joined: 08/22/2010
Juice: 18
Great, but where?

Identical to the previous reply:

As I am fairly new to Ubercart: do you have any instructions as to where and how I should paste this code?

Many thanks

Tammo ter Hark

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: Great, but where?

i'm not exactly sure if this would work but it appears that the address fields order is set in the uc_cart_checkout_pane.inc, so i'm guessing that if you created a copy of this for your theme and simply cut and pasted the code lines into a different order it would work without the code above. In UC 2.x-2.4 it looks to be around line 266 (for the shipping address) & 356 (for the billing address) where these start. if you can't override this page at the theme level there is always hacking the existing file but that's never recommended.

Edit: tested quickly on my test site by just re-ordering the lines in the default file, though I don't know exactly how to override this currently it will be easy if you figure that part out

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: Re: Great, but where?

also read here towards the end - http://www.ubercart.org/forum/support/11025/how_do_i_create_new_theme_fi...
and it appears if you want to use the code supplied above it goes into your themes template.php with the corresponding 'prefix'

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)

sittard's picture
Offline
Joined: 11/19/2010
Juice: 14
Solution using forms api

I might be missing the obvious but surely the easiest option is to utilise #weight :

function MY_MODULE__form_alter(&$form, $form_state, $form_id) {
  /**
   * Change checkout BILLING address fields order.
  */
  if ($form_id == 'uc_cart_checkout_form') { 
    $form['panes']['billing']['billing_city']['#weight'] = '1';
    $form['panes']['billing']['billing_zone']['#weight'] = '2';
    $form['panes']['billing']['billing_postal_code']['#weight'] = '3';
    $form['panes']['billing']['billing_country']['#weight'] = '4';
    $form['panes']['billing']['billing_phone']['#weight'] = '5';
   }
}
pushka's picture
Offline
Joined: 05/25/2011
Juice: 3
I thought the same, but...

Ubercart forms don't fully utilise Form API, so adding weight in this way makes no difference. For any other Drupal form, this would be the way to go.

So the more convoluted solution posted above is the answer here..

rcastera's picture
Offline
Joined: 09/14/2011
Juice: 8
Solution

For anyone looking for a clean solution for this, here ya go:

<?php
/**
* Implementation of hook_checkout_pane_alter().
*/
function YOUR_MODULE_checkout_pane_alter(&$panes) {
  foreach (
$panes as $key => $pane) {
    switch (
$pane['id']) {
      case
'delivery':
       
$panes[$key]['callback'] = 'YOUR_MODULE_checkout_pane_delivery';
        break;
    }
  }
}

function

YOUR_MODULE_checkout_pane_delivery($op, $arg1, $arg2) {
  require_once(
drupal_get_path('module', 'uc_cart') . '/uc_cart_checkout_pane.inc');

  switch (

$op) {
    case
'view':
     
$contents = uc_checkout_pane_delivery($op, $arg1, $arg2);

     

$contents['contents']['delivery_address_select']['#weight'] = -11;
     
$contents['contents']['delivery_first_name']['#weight'] = -10;
     
$contents['contents']['delivery_last_name']['#weight'] = -9;
     
$contents['contents']['delivery_company']['#weight'] = -7;
     
$contents['contents']['delivery_street1']['#weight'] = -6;
     
$contents['contents']['delivery_street2']['#weight'] = -5;
     
$contents['contents']['delivery_city']['#weight'] = -4;
     
$contents['contents']['delivery_zone']['#weight'] = -3;
     
$contents['contents']['delivery_postal_code']['#weight'] = -2;
     
$contents['contents']['delivery_country']['#weight'] = -1;
     
$contents['contents']['delivery_phone']['#weight'] = 1;
      return
$contents;
  }
}
?>