When a user checkouts out, they need to fill in some specific information which should be saved to the User entity.

Thus I need to modify the checkout form to collect the information I want, then save it to the User.

It seems like a cheeky way to simplify the process would be attaching User fields directly to the Commerce Order entity. Is this possible, or should I just load the User entity form and copy the fields I want in a hook_form_alter?

1 Answer 1


You could attach the fields from the user to the form, but you would need to handle saving the user in the form submit. You could in form alter do something like this

function hook_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'the form id') {
    $form['user_fields'] = array();
    global $user;
    field_attach_form('user', $user, $form['user_fields'], $form_state);

You also need to add validate and submit handlers in the form_alter in the validate handler do

 field_attach_validate('user', $user, $form['user_fields'], $form_state);

And in the submit handler do

field_attach_submit('user', $user, $form['user_fields'], $form_state);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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