Question

I want to show "Buy Now" button on listing page i.e. on category page, after click on buy now it will redirect to onepage checkout. I used "

<button onclick="location.href ='<?php echo $this->helper('checkout/cart')->getAddUrl($_product);?>′">Buy It Now</button>

" It will redirect to cart page but i need to redirect on onepagecheckout.

Was it helpful?

Solution

Use below code:

Buy now button code as below:

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

Ajax code as below:

<script>
  function addProductCheckout(addtocart,checkouturl)
     {
        jQuery.ajax({
                      url:addtocart,
                      success:function(data){
                          window.location.href = checkouturl;
                      }
                   });
      }
</script>

OTHER TIPS

Just send anthor parameter(return_url=$this->getUrl("checkout/onepage")) with add to cart url

Change to

<?php echo $this->helper('checkout/cart')->getAddUrl($_product).'?return_url=$this->getUrl("checkout/onepage")';?>">

from

<?php echo $this->helper('checkout/cart')->getAddUrl($_product);?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top