I am new to Magento, using Magento 1.9. with a custom theme. I successfully created buy now button on addtocart.phtml
by the following codes
<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) ?>
But am confused in where to paste below javascript on my view.phtml
? can anyone say exactly next to which function or step number, I should paste these scripts?
<script>
jQuery.ajax({
type:"GET",
url:location,
success:function(data){
window.location.href = "http://www.your-site.com/checkout/onepage/";
}
});
</script>
I planned to have 2 buttons, without disturbing each other: When someone clicks
Buy Now button which should redirect to
checkout/onepage
Add to cart button should do its default
checkout/cart
Thanks in advance. Any suggestions are very welcome! 🙂
Best Answer
Kindly open app/design/frontend/package/theme/template/catalog/product/view.phtml
Add below line into
<form>
TagPut below button at anywhere where you want
Now open app/code/core/Mage/Checkout/controllers/CartController.php
First of all move this file into the local folder and change the code as below instructions
Put below line in
_goBack()
function at very firstFInd the line $this->getResponse()->setRedirect($backUrl); and replace this line as below code
Code Taken from this link http://chandreshrana.blogspot.in/2016/01/how-to-add-buynow-button-on-product.html