Tags/topics: 
3
Answers
Vote up!
2
Vote down!

Need to remove "Add to cart" button and "Enter quantity" from product display

Hi everybody,
I decided to install Commerce Kickstart 2.19 and import products from Virtuemart for my client. At the beginning I need only product catalog without any payments and checkouts. Just to remove these two things. How to do this elegant, secure and simply without uninstalling modules like Cart, Order, Commerce Kickstart Product etc.?

TIA!

Asked by: Przemek B.
on October 21, 2014

Comments

I'd like to hear about solutions too.

I've been trying to set up a Commerce Kickstart site as a product catalogue, but my product attributes (color, size etc) are rendered inside the "Add to Cart" form, so if you disable "Add to Cart" you also deprive customers of the ability to toggle between your different colours, different sizes, etc.

Is there any way to keep the attributes as selectable drop-downs without having "Add to Cart"?

- Alan Cocks on October 21, 2014

3 Answers

Vote up!
2
Vote down!

Two ways spring to mind, although they're pretty similar and you'll need to test which works better for you:

In both create a HOOK_form_alter() function and then either:
1/

<?php
 
function HOOK_form_alter(&$form, &$form_state, $form_id) {
  if (
0 == substr_compare($form_id, 'commerce_cart_add_to_cart_form_', 0, strlen('commerce_cart_add_to_cart_form_'))) {
  
$form['submit']['#disabled'] = TRUE;
  }
}
?>

You can then use CSS to just hide the button if you choose

OR
2/

<?php
 
function HOOK_form_alter(&$form, &$form_state, $form_id) {
  if (
0 == substr_compare($form_id, 'commerce_cart_add_to_cart_form_', 0, strlen('commerce_cart_add_to_cart_form_'))) {
   
$form['submit']['#access'] = FALSE;
  }
}
?>

Which will just remove the add to cart button competely

Andy @ BlueFusion
Posted: Nov 3, 2014

Comments

OK, I placed this piece of code in template.php file and it works fine

<?php
function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
    if (
0 == substr_compare($form_id, 'commerce_cart_add_to_cart_form_', 0,
           
strlen('commerce_cart_add_to_cart_form_'))) {
               
$form['attributes']['field_top_size']['#access'] = FALSE;
               
$form['quantity']['#access'] = FALSE;
               
$form['submit']['#access'] = FALSE;
            }
}
?>
- Przemek B. on November 6, 2014

I tried this code and it worked fine. However, I am looking for a partial removal of the cart button, for example, I would like to remove it from one of my product types only.

Is there any way of limiting the cart button removal to only one product type or content type?

Many thanks

- A A on December 26, 2014

You can test for the product type as well:

function HOOK_form_alter(&$form, &$form_state, $form_id) {
  if (0 == substr_compare($form_id, 'commerce_cart_add_to_cart_form_', 0, strlen('commerce_cart_add_to_cart_form_'))) {
    $node = menu_get_object();
     if ($node && $node->type=='YOUR_PRODUCT_TYPE') {
       $form['submit']['#access'] = FALSE;
    }
  }
}
- Andy @ BlueFusion on January 3, 2015
Vote up!
0
Vote down!

You should be able to go to the Product Display (node) Display Settings and hide the Product reference field and hide any of the injected product attribute fields that you wouldn't want displayed.

Josh

Josh Miller
Answer by: Josh Miller
Posted: Oct 21, 2014

Comments

Vote up!
0
Vote down!

That is probably fine if you have a one-to-one relationship between product items and product displays (nodes), but in my case I have multiple product items per display node.

If I hide the Product Reference field in my Product Display then I lose the "Add to Cart" form, and with that I lose the ability to select from my attribute drop-down attribute fields and so swap from one variation of my product to another.

Is there a way to hide the "Add to Cart" button only, and still keep the rest of the fields in the "Add to Cart" form?

Answer by: Alan Cocks
Posted: Oct 21, 2014

Comments