There may be some instances where you may not want your users to change their quantity on the cart page. An example may be where you want to limit an item to one per order. There are many ways to limit in the product’s node page, but the cart page presents a loophole where the user may edit their quantity.

Replace with MY_MODULE with the name of your own custom module.

Replace┬áCONTENT_TYPE_NAME with the machine name of the content type of the product. Usually this will be “product” unless you defined your own custom product class.

function MY_MODULE_form_alter(&$form, &$form_state, $form_id){
    switch($form_id) {
        case 'uc_cart_view_form':
            $items = uc_cart_get_contents();
            for($i = 0; $i < count($items); $i++) {
            if(isset($form['items'][$i]['#entity']->type) && $form['items'][$i]['#entity']->type == 'CONTENT_TYPE_NAME') {
            $form['items'][$i]['qty']['#disabled'] = true;

Alternatively you may set the quantity limit here as well with:

$form['items'][$i]['qty']['#default_value'] = 1;

2 Responses to “Drupal 7 Ubercart 3 Disable cart change quantity field”

  1. Antero

    I can’t seem to get this module to work, it gives me WSOD

    • Antero

      Haa! I was able to get it to work. Dunno why it didn’t work in the first place. Thank you heaps!

Comments are closed.