Vote up!
Vote down!

How to disable quantity widget on shopping cart page.

Hi there

I want to disable the quantity widget on shopping cart page on the basis of a product custom field value.

I have created a custom field of type boolean on product type and what I need to do is if the field value is '1' then any products with value '1' in the shopping cart should have quantity widget disabled..

I can disable the quantity widget on the basis of product type and product id but that does not work for me. Below is how I can manage to do using product id.

function bcc_search404_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'views_form_commerce_cart_form_default') {
global $user;
$cart = commerce_cart_order_load($user->uid);
//$in_cart = FALSE;
foreach (commerce_order_load_multiple(array(), array('status' => 'pending'), TRUE) as $order) {
$product_ids = array();
foreach (entity_metadata_wrapper('commerce_order', $cart)->commerce_line_items as $delta => $line_item_wrapper) {
if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
$product_ids[0] = $line_item_wrapper->commerce_product->raw();

if (in_array(221, $product_ids) || in_array(207, $product_ids)) {
foreach ($form['edit_quantity'] as $index => $line_item) {
if (is_numeric($index)) {

// compare the current shopping cart line item ID to the form line item ID

if ($line_item_wrapper->raw() == $form["edit_quantity"][$index]['#line_item_id']) {
$form['edit_quantity'][$index]['#attributes']['readonly'] = 'readonly';
$form['edit_quantity'][$index]['#attributes']['disabled'] = TRUE;
$form['edit_quantity'][$index]['#attributes']['title'] = t('This quantity cannot be changed.');




Asked by: Faadz
on March 10, 2016

1 Answer

Vote up!
Vote down!

To remove quantity go to (structure->content types -> product display -> manage display)

Answer by: coolgbb
Posted: Apr 5, 2016