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.

  • try this helper('checkout/onepage') – Magento 2 Apr 21 '16 at 10:00
  • no, its didn't work from listing page. I need to redirect on onestepcheck. – Mace Long Apr 21 '16 at 10:05
  • i tried with this also $checkout_link = Mage::helper('checkout/url')->getCheckoutUrl(); <button onclick="location.href ='<?php echo $checkout_link;?>'">Buy It Now</button> it will redirect, but product is not added in cart :( – Mace Long Apr 21 '16 at 10:09
  • update your checkout page url – Magento 2 Apr 21 '16 at 10:09

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:

  function addProductCheckout(addtocart,checkouturl)
                          window.location.href = checkouturl;
| improve this answer | |

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")';?>">


<?php echo $this->helper('checkout/cart')->getAddUrl($_product);?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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