I have been scratching my head for nearly three hours trying to figure out how I could add a "checkout" button to a page once a product has been successfully added to the shopping cart.

I have created a module that uses the checkout_cart_product_add_after event but I have hit a brick wall.

I there a simpler method to do this?

After some input from @Sven I scrapped the Observer method. I'm try to write an IF clause that will check if an item is in the shopping cart but not having much success IF anyone can share the correct argument to pass please let me know...

IF clause

<?php $totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); ?>
<?php if($totalItemsInCart) ?>
    <button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="whatever btn-continue" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
<?php else: ?>
    //Nothing to delclare
<?php endif ?>

2 Answers 2


It's pretty easy to do this with a block*. Define your block**:


class YourCompany_YourModule_Block_Checkoutbtn extends Mage_Checkout_Block_Cart_Sidebar
    public function canDisplayCheckoutButton()
        return $this->getItemCount()>1;

And then reference it in your template:

<?php if($this->canDisplayCheckoutButton()): ?>
    <button class="btnCheckout"><span><?php echo $this->__('Proceed to Checkout'); ?></span></button>
<?php endif; ?>

To add this block to a particular place on your product page all you have to do is add this to your theme's local.xml (if it doesn't exist, create it):

    <reference name="content">
        <block type="core/text_list" name="pdp.checkout.buttons">
            <block type="yourcompany/checkoutbtn" template="path/to/template.phtml" name="checkout.onepage.button" alias="btnCheckout"/>

* Be aware on Magento Enterprise if full page cache is enabled this will display buttons for customers who have no items in the cart unless you create a hole-punch.

** You will need to define your block in your module. See other how-to's to get this set up properly.


I'm not sure you can do it this way. First problem that I see is that the order of events is not guaranteed in any way. It means that your events can be fired/observed in random order.

Secondly it smells a bit fishy when I think about request flow but it's quite late and I cannot figure out what it is exactly.

Why not to add "Checkout" button to a block with a condition that checks if there's anything in the cart?

  • Thanks for the reply, You have given me some light as I wasn't so keen on the Observer method either. I'm trying to write an IF clause to check if an item is in the cart but not having much success see edit.. Commented Nov 6, 2013 at 22:52

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.