Skip to content

Instantly share code, notes, and snippets.

@rgpublic
Created October 11, 2022 13:25
Show Gist options
  • Save rgpublic/1efe2832c4dd98d9c52312c2b4622385 to your computer and use it in GitHub Desktop.
Save rgpublic/1efe2832c4dd98d9c52312c2b4622385 to your computer and use it in GitHub Desktop.
Add salutation field to billing address in Drupal Commerce
<?php
function hook_commerce_inline_form_customer_profile_alter(&$inline_form,FormStateInterface $form_state,array &$complete_form) {
$inline_form['#after_build'][]='after_build';
}
function after_build(&$form) {
$address=&$form['address']['widget'][0]['address'];
$address['field_salutation']=$form['field_salutation'];
$address['field_salutation']['#weight']=-3;
$address['container1']['#weight']=-2;
$address['organization']['#weight']=-1;
$address['country_code']['#weight']=1;
unset($form['field_salutation']);
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment