Magento – Hot to add buy now button on product page which will take the customer to checkout page of that product only

magento-1.9magento-community

I'm new to Magento. I want to add the buy now button along with the Add to cart button on the product page. I have searched for that, I found this solution :

<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/onepage') ?>')"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>

<script>
    function setcheckoutLocation(location,chkout)
    {
        jQuery.ajax({
            type:"GET",
            url:location,
            success:function(data){
                 window.location.href = chkout;
            }
        });
    }
</script>

But it add the product to cart and then redirects to onepage and in the checkout process, all the products that are in the cart are added.

Is There any way that the product which we have selected for buy now will only be added to the checkout process regardless of products in the cart. Thanks in advance.

Best Answer

Hello @Srikant you have to create a form on the product page and the action should be checkout link :

<?php 
   $product = Mage::getModel ( 'catalog/product' )->load ( $product_id );
   $url = Mage::helper ( 'checkout/cart' )->getAddUrl ( $product, array ('qty' => 1 ) );
?>

In url $product is product object

<form method="post" name="form-name"action="<?php echo $url;?>">
       <button type="submit" class="btn_goto"><?php echo $this->__('Buy Now') ?>   
</form>

Now clicking on the buy now you will be redirected to the checkout page directly. The form should be individual for each product.

Related Topic