Tag Archives: buy now button

Adding buy now button to Magento (Skip the cart)

Here’s a task that keeps coming up again and again.

I’ve come across numerous ways to do this by editing the Observer file, adding a new action etc yet they all seem like over kill!

Why not do it nice and easy via jQuery? Nothing to add apart from a couple of bits of code, check this out…

Add this into your view.phtml file (app/design/frontend/your_template/default/template/catalog/product/view.phtml)

<script>
function setcheckoutLocation(location)
{
jQuery.ajax({
type:”GET”,
url:location,
success:function(data){
window.location.href = “http://www.your-site.com/checkout/onepage/”;
}
});

}
</script>

I dropped it in at line 187, just after the Java that follows on from the </form> tag.

Now head over to your addtocart.phtml file (app/design/frontend/your_template/default/template/catalog/product/view) and add in:

<button type=”button” title=”Buy Now” class=”button btn-cart” onclick=”setcheckoutLocation(‘<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><span>Buy Now</span></span></button>
<?php echo $this->getChildHtml(”, true, true) ?>

I put this in at line 40, straight after the ‘Add to cart’ button, make sure its within the <div class=”add-to-cart-buttons”> DIV and it will follow on nicely after your Add to cart button. Or remove the Add to cart button.

I opted to keep both buttons to tempt a upsell/multibuy.