Drupal Commerce add to cart form alter I'm dipping my toe into modifying a Drupal Commerce form. I want to change a few things with the hook they provide. The form id is: commerce-cart-add-to-cart-form-626 and the id of the submit button is edit-submit. 

I created a Drupal module called jch_test

function jch_test_form_commerce_cart_add_to_cart_form_alter(&amp;$form, &amp;$form_state) {
  $line_item = $form_state['line_item'];
  $product = commerce_product_load($line_item-&gt;commerce_product[LANGUAGE_NONE]  [0]['product_id']);
  if ($product-&gt;type == 'product') {
    $form['submit']['#value'] = t('Test');
  }
}


...the module loads, but the code does not fire. What am I doing wrong? I'm sure this is a total noob mistake.
Try something like this:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MY_MODULE_form_commerce_cart_add_to_cart_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  //drupal_set_message($form_id);

  $form['submit']['#attributes']['value'] = t('Buy Now');

  /*
  $current_product = $form_state['default_product'];
  if ($current_product-&gt;type == 'product') {
    // Make alternations for products...
  }
  */

}


You can use the $form_id and/or $current_product to make custom alterations for a specific product(s) and/or product type(s).

Flush Drupal's caches so your custom form alteration hook will be recognized.

Note, I'd also like to point out that once a user changes a value on the add to cart form, and the form is reloaded via AJAX, MY_MODULE_form_commerce_cart_add_to_cart_form_alter() will be called again, which is good.

However, it appears the $form_state['default_product']-&gt;language value may only be present the first time the page is loaded. Once the form is reloaded via AJAX, the language value may be empty in this hook, so watch out if your code is depending on it being there!