In my Magento site product view page, I need to replace the button "Add to Cart" to "Buy Now" button in I want like to the "Checkout" page.

Example : if the customer clicks the "buy now" button the link will going to the checkout page.

enter image description here

  • link to checkout page??? – Shyam Krishna Sreekumar May 13 '15 at 11:51
  • if any one click the "buy now" button the product will going to checkout page. – Mohamed May 13 '15 at 12:51
  • Do you want to do add to cart of that product and go to checkout page right? – Sunil Patel Oct 29 '17 at 5:57
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Buy Now'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
<?php endif; ?>

enter image description here


You have to change the addtocart.phtml file inside your current theme, otherwise it will not work

  • i already Change the addtocart.phtml file code but it's not working. – Mohamed May 13 '15 at 14:15
  • Are you sure you edited the correct file? If you changed the file in the base folder, it will not change anything, you have to change the file in your current theme. – Marleen Berg May 13 '15 at 14:17
  • yes sure. because in my themes don't have this file i copy from base folder. and pest in my correct themes – Mohamed May 13 '15 at 14:19
  • and don't forget to clear cache – Marleen Berg May 13 '15 at 14:22
  • how to clear cache? – Mohamed May 13 '15 at 14:24

Have you cleared the cache? Go to System>Cache Management> Flush Magento Cache & Flush Cache Storage, also you can delete the cache folder from your server (/var/cache).

  • it's already try this but it's not working. how to delete the cache from server? please tell me how to do that? – Mohamed May 14 '15 at 10:22
  • connect to your server with a ftp client like Filezilla and under the root path where you installed magento you have a folder called var and there you will see the cache folder. Just delete it. – Mihai Cata May 14 '15 at 10:34
  • it's also done but not working? – Mohamed May 14 '15 at 11:14
  • What have you set under System>Design or System>Configuration>Design>Package,System>Configuration>Design>Themes ? – Mihai Cata May 14 '15 at 11:20
  • in magneto or server? – Mohamed May 14 '15 at 12:23

Try this, hope it can help you:

Magento generates an add to cart url for add to cart buttons.

It's in the form of

http://{YOUR SITE NAME}/checkout/cart/add/uenc/{Base64 Encoded Redirect Url},/product/{PRODUCT ID}/form_key/{FORM KEY}/

$url = strtr(base64_encode($url), '+/=', '-_,'); // for base64 encode

$form_key = Mage::getSingleton('core/session')->getFormKey(); // for getting form_key

if you use http://{YOUR SITE NAME}/checkout/onepage as redirect url magento redirect you directly to checkout after product added to cart.

You only have to make a button which redirects to this url. // onclick=setLocation(url);


Go to the path app >design>frontend>base>default>template>catalog>product>view
File addtocart.phtml copy to your theme folder and edit line no. 28 add to cart to buy now thats it

  • thank you for your replay but Im try like your way but it's not working. can you tell me please how i can do this please. – Mohamed May 13 '15 at 13:05

Go to admin panel -> system configuration -> design and check to see what the package name and template are. Write this down, and navigate to your theme and do what the others have suggested. Copy the addtocart.phtml into app/design/frontend/package/theme/template/catalog/product/view and edit it appropriately.

  • yes edit same way but it's not working – Mohamed May 13 '15 at 14:24
  • under the design tab, what does it say under Current package name and theme-> template – cleong May 13 '15 at 14:30
  • yes inside view folder addtocart.phtml right. – Mohamed May 13 '15 at 14:31
  • what does the admin panel say? what package are you using? – cleong May 13 '15 at 14:32
  • sorry what is the meaning of package ? please – Mohamed May 13 '15 at 14:36

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.