Disable Quantity Input for specific product (By Prodyct Type)

Public

</> CopyGet raw version
php
  1. function YOUR_MODULE_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state)
  2. {
  3. /**
  4.   * Disabling Quantity Editing For 'book_product'
  5.   */
  6. foreach($form['edit_quantity'] as &$quantity) {
  7.  
  8. if((!is_array($quantity))||(!isset($quantity['#line_item_id']))){
  9. continue;
  10. }
  11.  
  12. $line_item = commerce_line_item_load($quantity['#line_item_id']);
  13. $product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
  14. if('book_product' === $product->type){
  15. $quantity['#disabled'] = TRUE;
  16. }
  17. }
  18. }