Tags/topics: 
1
Answers
Vote up!
6
Vote down!

Setting Custom Fields at Checkout

Our subscription site requires that users submit address information pre-checkout. In order to make the process a little easier on the users we wanted to pass information back into the checkout form (both the billing and shipping fields). We have the information both in the line-items and the order but are unable to adjust the form values in checkout via the hook_form_alter. Is it possible to change it via hook_commerce_checkout_pane_info_alter? If so how? It doesn't appear that there are callbacks for altering the form before presenting it.

Repost of
http://drupal.stackexchange.com/questions/31509/commerce-setting-custom-...
http://drupal.org/node/1589134

Asked by: dannymacom
on June 16, 2012

1 Answer

Vote up!
2
Vote down!

You should be able to do this using hook_form_alter(), but I may recommend a different approach. There's actually a hook that gets invoked when a customer profile is created, which is the entity type that store address and related information. This is the entity that gets created and referenced from the order by the checkout panes like "Billing information."

So, what you could do is implement hook_commerce_entity_create_alter($entity_type, $entity) and look for a cart order to pre-populate the $entity object with your billing information when the $entity_type is commerce_customer_profile. This would have the added benefit of being available elsewhere besides just on the checkout form.

You might also look at the Commerce Addressbook module's approach, which actually creates the customer profile for the customer in advance and then establishes the reference to the customer's default billing profile when the order is first created.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Jun 27, 2012