Is there a way to change the quantity widget in the Drupal Commerce cart view from a textfield to a selectbox? And then refresh the page when the selectbox is changed without making the user press the Update cart button?

 * Implements hook_form_alter().
function mymodule_form_alter(&$form, &$form_state, $form_id) {
 if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
   if (isset($form['quantity']) && ($form['quantity']['#type'] == 'textfield')) {
     $form['quantity']['#type'] = 'select';
     $form['quantity']['#options'] = drupal_map_assoc(range(1,10));
     $form['quantity']'#default_value' => 1,


| improve this answer | |
  • This solution looks like it is for the quantity in the add-to-cart form on a product display page, not the quantity field that shows up in the cart form (View). – Craig Apr 22 '16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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