20

I was wondering how to disable Add to Cart button on a few specific products, and I found an abandoned guide on how to do this, which worked, but it was somewhat incomplete, as it only was just a solution on the product view pages, and not on category list or grid pages.

I will answer my own question here in 8 hours (since I need to wait 8 hours, since my reputation is below a certain point), after I explain the first steps, and my answer will be the missing 3rd Step that I had to figure out for myself. I'll try to make this easy to follow:

[Step 1]

[1]

Create an attribute that you will use on products you don't want an Add to Cart button on. In the Admin dashboard, go to...

Catalog > Attributes > Manage Attributes > Add New Attribute

Name your attribute whatever you like, for example: "No_cart_button"

With the Properties:

Attribute Code: No_cart_button
Catalog Input Type for Store Owner: Yes/No


Use in Quick Search: No     
Use in Advanced Search: No  
Comparable on Front-end: No
Visible on Product View Page on Front-end: No   
Used in Product Listing: YES
Used for Sorting in Product Listing: No

With Manage Label / Options:

Admin: Disable Add to Cart
English: Disable Add to Cart

Now save this attribute.

[2]

Assign your new attribute to a group, so you can use it. I used "Default". Go to...

Catalog > Attributes > Manage Attributes Sets > Select Set

Now save this attribute set.

[Step 2]

We'll add some code to view.phtml

app/design/frontend/default/theme/template/catalog/product/view.phtml

Find this block of code:

    <?php if (!$this->hasOptions()):?>
    <div class="add-to-box">
    <?php if($_product->isSaleable()): ?>
    <?php echo $this->getChildHtml('addtocart') ?>
    <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
    <span class="or"><?php echo $this->__('OR') ?></span>
    <?php endif; ?>
    <?php endif; ?>
    <?php echo $this->getChildHtml('addto') ?>
    </div>
    <?php echo $this->getChildHtml('extra_buttons') ?>
    <?php elseif (!$_product->isSaleable()): ?>
    <div class="add-to-box">
    <?php echo $this->getChildHtml('addto') ?>
    </div>
    <?php endif; ?>

ok, now replace it with this block of code:

<?php
//Checks if the "Disable Add to Cart" variable is set to 'Yes': 
if(($_product->getAttributeText('No_cart_button')) == "Yes"){
//If set to Yes, tell PHP what to output:
echo "This Product is not available online, please call our representative if you wish to purchase this.";
}
//If set as No, then show the 'add to cart box' as usual.
else {
?>

<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php elseif (!$_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php endif; ?>

<?php
}
?>

This code checks if No_cart_button is set to yes. If it is set to yes, it outputs the code, which will remove the add to cart button and instead show text that says, "This Product is not available online, please call our representative if you wish to purchase this.".

Ok these 2 steps are complete, and removes Add to Cart on the product view page.

But, this does not remove the "Add to Cart" button on Category list pages. Now, we want to make a "View Details" button on category list pages, instead of "Add to Cart" button.

[EDIT]

Answer:

kevinkirchner is correct, we will add this logic to list.phtml now. We already made sure the attribute settings for "Used in Product Listing" is set to 'YES'.

Ok,

[Step 3]

We will make it so when Disable Add to Cart is set to Yes, it also disables "Add to Cart" button on Category list pages.

Go to list.phtml

app/design/frontend/default/theme/template/catalog/product/list.phtml

and search this file for:

<?php if($_product->isSaleable()): ?>

It should appear 2 times in this file.

Right below this line, insert the following code

<?php
if(($_product->getAttributeText('No_cart_button')) == "Yes"){ ?>
<p><button type="button" title="<?php echo $this->__('View Details') ?>" class="button btn-cart" onclick="location.href='<?php echo $_product->getProductUrl() ?>'"><span><span><?php echo $this->__('View Details') ?></span></span></button></p>
<?php 
}
else {
?>

Then right below your code that creates the normal 'Add to Cart' button, you'll see

<?php
}
?>

right below this, insert another of the same bit of code:

<?php
}
?>

Ok, now do this same exact 2 steps to the other block of code in this file where you find

<?php if($_product->isSaleable()): ?>

You must do this twice, because the first time is for List View, and the second time is for Grid View.

  • This is not I website for 'showcase' or 'show off'. IT's Q&A. I recommend that this 'so called' question be closed. – Marius May 13 '13 at 18:56
  • Oh, I was hoping to help people - Should I instead delete this or leave it so it's searchable? – stephen wise May 13 '13 at 18:58
  • @Marius I don't think this is 'showing off' so much as the OP needs to work up enough rep to post their own Answer. I vote to close until that time, then will address a reopen or you can re-post your Q&A. – philwinkle May 14 '13 at 18:53
  • Sorry guys, I should learn the ways of Stack Exchange better. I'll learn with experience, too, thanks for helping me understand these things. – stephen wise May 15 '13 at 12:09
7
  1. Make sure your attribute is available on product listing page by setting "Used in Product Listing" to "Yes" when editing your attribute — screenshot

  2. Add your logic to template/catalog/product/list.phtml to show Add to Cart/View details button

  • Yep! I'm going to select your answer. I will provide more specific details in an edit on my original post. – stephen wise May 13 '13 at 18:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.