How to use hook_form_alter to target a specific drupal commerce form? I have a fairly basic question I think. I've written a module that uses hook_form_alter to alter the fields in a product form.

But now I'd like to change the fields in the form for a different product and I was thinking of using my custom module to do so.

However, when I use the Devel module to try and find the specific $form_id for each of my created product forms I see they ALL have the SAME name: commerce_checkout_form_checkout. Soooo, I'm not sure how to target a specific form.

Moreover, I've used dpm() to check the variables in the forms and they all have the exact same values for everything. Even across product types. The only value that is different is #build_id but this changes for every form load so it can't be targeted.

Anyone know how to do this?
To add or alter the pane forms on the checkout page, for maximum compatibility, you should use the Commerce API.

Define new panes in:

hook_commerce_checkout_pane_info

Alter existing panes: 

hook_commerce_checkout_pane_info_alter

For example, you could alter the checkout_form callback for a checkout pane to add your customizations.


  checkout_form($form, &amp;$form_state, $checkout_pane, $order): returns form elements for the pane’s checkout form fieldset


You could also add your own custom checkout pane for your custom design there.

You can refer to the existing pane callback to first include or replicate the checkout pane. 

Note: I posted a similar answer for adding a custom validate handler to a checkout pane a while ago here: https://drupal.stackexchange.com/a/87061/7153