I need an add to cart and buy now button. It is working fine but when I click buy now button, nothing is happening and after a couple of seconds the page is redirecting to the cart page. I need to redirect the page once I click buy now button

Here is the code I am using in addtocart.phtml

 <button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/cart/') ?>')"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>

 function setcheckoutLocation(location,chkout)
                     window.location.href = chkout;

1 Answer 1


When you click the button, there's an Ajax call being done. This takes some time and after that it is redirecting. If this Ajax call is not being done, then the product will not be added to the cart.

I think you mean that this is a problem in user experience. You could solve this by making the button change, once you have clicked it, so the user knows something is happening. There are tons of examples of buttons with loading effects: https://google.com/search?q=button+loading&tbm=isch

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