We'd like to hide the Proceed to Checkout button on the Cart page if any quantity greater than 1 total of a set of 3 products are in the cart.

In other words, the customer can only buy a max of ONE of the following Product IDs: 4, 44, and 47. I'd like to simply check the cart and total a count of all 3 of those Ids in their cart. If it's any more than 1 total, then I want to hide the Proceed to Checkout button (and likely echo a note like "You can only buy 1 total of the special products")

I'm using the link.phtml template and figured I need to cycle thru the Cart quote to tally the count in cart of those three products. And of course, if more than 1 then display the message, else display the checkout button.

I've looked at and tried other examples of checking for products in cart, but can't wrap my head around checking for an array of 3 products and tallying the total count. Any help would be appreciated.

2 Answers 2


From an answer of mine over on StackOverflow in 2013:

Using an event observer you could listen to the postdispatch of the cart view event and suppress the button from displaying. This is a builtin functionality.


And the observer method would look like:

public function deletePostdispatch($observer)





  • Sorry, but I'm not clear with your example on how I specify the 3 products that I want to check for (being a total of 1 or less) before providing the Checkout Button. Commented May 10, 2016 at 5:22
  • Are you a developer or do you have a developer handy? This example is almost verbatim what you need.
    – philwinkle
    Commented May 10, 2016 at 5:35
  • I'm a developer but not well-versed on Event observers so some hand-holding would be appreciated. You are taking into account that I need to suppress the Proceed to Checkout if ProductA qty + ProductB qty + ProductC qty is > 1 total?thanks Commented May 10, 2016 at 5:54
  • @RichYessian the line Mage::getSingleton('checkout/session')->getQuote()->getItemsCount()==1 is saying "give me the entire total number of all items in the cart". In this case it's only true when there is exactly one item in the cart. You could modify this to be any other value. Beyond that if you're looking for Specific items in the cart I'd follow this approach magento.stackexchange.com/a/45855/336
    – philwinkle
    Commented May 10, 2016 at 6:04
  • Thanks for trying to help me, but not sure I'm being clear. Example: I have 20 products in my store, 3 of those products are the "special" ones. If customer has more than 1 of any special products, then they shouldn't checkout. But they need to be able to add other products to their cart. So, they could have 12 other products in cart. But only ONE of the 3 products. So: if they have 1 of specialprodA, and 1 of specialprodB, then no checkout. If they have 2 of specialprodA, then no checkout. If they have just one of specialprodB and 10 other products, then they can checkout. Am I confused? thx Commented May 10, 2016 at 15:31

I essentially figured out what I needed by using the getQuote and getAllItems to iterate thru. The below code is quick and dirty and needs cleanup, but I just needed to know if customer has more than 1 of any of the 3 productIds in total in cart.

// Product IDs of Free Products
    $arrayProds = array(4,44,47);
    $count = 0;

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $productId = $item->getProductId();
    if (in_array($productId,$arrayProds)){
            $productQty = $item->getQty();
            $count = $count + $productQty;
            if ($count > 1){
                // We know that we have too many free products in cart, and can do whatever we want here

For now this works, but understandably there's probably a better way of doing this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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