5

I'm using commerce and want to alter the checkout form in a custom module to prepopulate certain fields and hide them.

However, I'm not able to do this using hook_form_alter() as well as hook_commerce_checkout_pane_alter().

Here's my sample code:

function MYMODULE_form_alter($form, &$form_state, $form_id) {
  global $user;

  switch ($form_id) {
    case 'commerce_checkout_form_checkout':
      // Rename the button for example.
      $form['buttons']['continue']['#value'] = t('Overridden value');
      break;
  }
}

How can I edit fields that are displayed on checkout?
Is there some other hook I should use?

Thanks!

2 Answers 2

5

I think you're looking for commerce_checkout_form() (commerce_checkout_form_checkout doesn't exist as far as I can tell from greping Commerce's code):

function MYMODULE_form_commerce_checkout_form_alter($form, &$form_state, $form_id) {
  ...
}

or

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'commerce_checkout_form':
      ...
    break;
}
3
  • Thanks for your answer, but I'm running into the same issue - the hook works and I can dpm() the form, but nothing is altered for real. Will try this now on a clean install and see if I can narrow down the issue. Will post back shortly. Mar 20, 2014 at 15:42
  • 1
    Oh right...it'll be this then: MYMODULE_form_alter($form. Can't alter an external var unless you pass by reference :)
    – Clive
    Mar 20, 2014 at 15:44
  • Yep, that was it - I was missing the & in the $form argument :) Thanks! Mar 20, 2014 at 20:23
1

Use form_alter to customize commerce checkout page submit button values.

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'commerce_checkout_form_checkout':
      if (isset($form['buttons']['continue']['#value'])) {
        $form['buttons']['continue']['#value'] = t('Overridden value');
      } 
      break;
  }
}

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.