Discussions

How do you remove the "Add to Cart" button?

I really like the Add to cart form. In the T shirt example, it's intelligent enough to update the pull downs for the products I actually have (I love seeing the image update when I pull down a black or a white T-shirt). At the moment though, I simply want to display all the products I have, allowing the visitor to look at different colours and see the sizes available in each range (with each range having its own product display). So I don't want the "Add to cart" button but I want everything else. How can I do this? Also, I'd like to put things like colour and size on the same row, not below each other. Can I do this?

(Finally, a question I'm sure is silly but how do I modify the default home page? It doesn't seem to be a view and I'd like to have something fairly Bland" for my site!)

Thanks (I've still a lot to learn!)

Posted: Feb 1, 2012

Comments

frizi on February 4, 2012

Hi,
The add to cart is eighter generated at your view or within the product display.
In case of view, click on the field and check in "Exclude from display".
In case of product display, go to "admin/structure/types/manage/product_display/display" and set the Add to cart line the hidden setting.

The default Drupal page can be set at "/admin/config/system/site-information" at Default front page

Regs

PedroKTFC on February 4, 2012

Thanks for your reply frizi. I don't think I was clear enough. I want everything that's in the Add to cart form apart from the add to cart button itself. The add to cart form is perfect for showing all of the products available for a product display. At the moment, I don't want a shopping cart at all, I simply want a site for information.

I've found the php code where the button is developed so my next idea will be to try and clone that code and have a version without the button. As I'm a newbie php programmer, this might be interesting! :o) If there's a better way though, don't hesitate to suggest it!

Btw, thanks for the default Drupal page, doh, I should have spotted that!

frizi on February 4, 2012

Hi, did you checked at the address which I've mentioned to set the Hidden setting of the Add to cart button? does it still appears?

PedroKTFC on February 5, 2012

But by setting it to hidden I lose everything about the Add to cart form (unless I've misunderstood you), all I don't want is the button to add an item to the cart itself. I've now found that I can get rid of the button by simply commenting out 4 lines in the file commerce_cart.module. If I can't find a better or more proper way, I think I'll end up cloning this file and having my own version of the Add to cart form but without the button.

itamair on February 7, 2012

Try to manage this with the Field permissions module (http://drupal.org/project/field_permissions).
You set in the product reference field which role can view/edit, etc. this field. It may result in Add to chart button being hidden, while all the others fields that you expose in the product display will show ...

It is perfect as it let's you define the behavior for different roles ...
It works for me, and I hope will for you too.

PedroKTFC on February 11, 2012

That's actually a very useful module but it doesn't do what I want. I've (hopefully!) provided a diagram of what I'm trying to achieve. All I want is to get rid of the Add to cart button. I have managed to get rid of it by editing the add to cart form code. Problem with that is I upgraded my Drupal commerce and of course the edits were lost. Is there a valid way of editing code in such a way that upgrades and bug fixes are also incorporated?

p55mac on February 7, 2012

In the product entity form set the Status to Disabled

Then hide the product not available button with CSS

.out-of-stock .form-submit .form-button-disabled, .form-button-disabled {
display: none;
}

PedroKTFC on February 11, 2012

Sorry but I don't understand what you're suggesting. I'm a newbie so some of the jargon is confusing. For example, I'm not sure what a form is. Is it just a set of php code (unlike, say, a view which I can configure in the browser without having to edit any code)? Can you point me more directly at what you mean (and please see my last reply above where I hope I've made my question clearer).

PedroKTFC on February 16, 2012

It's taken me a while but I've finally cracked it! I've used hook_form_FORM_ID_alter() (that took me some learning and meant I had to create my own, admittedly trivial, module!). So in my module I've got the following which sets #access for the submit form to false which stops it being rendered (see http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc...).

In the future, I'll be able to extend this to disable the button on certain conditions (say when there's no stock but I want to show what combinations are possible). It would also presumably be an easy way of changing, say, the text for the button, such as "Buy" instead of "Add to cart".

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

// Disable the Add to Cart submit button

$form['submit'] = array('#access' => FALSE);

}

toby53 on November 11, 2012

Thanks so much
I had to expose my new site to the internet for for the initial PCI testing but need a way keep people from ordering products.
This worked for me. It removed the add to cart button on both forms and view lists.