I'm trying to add a new extra "add to cart" called (Send as a gift) button in product view. The functionality of this button has to be a little different than the original button. When i press this second button , it has to redirect directly to checkout .

I mentioned that the original button is not redirect. So , in conclusion , first button does not need to redirect you to checkout, but the second it is necessary.

Can anyone can give me some ideas , how to do this? I am using magento 1.9 Thanks in advance!

2 Answers 2


Try this one!

In your app\design\frontend\[package]\[theme]\template\catalog\product\view\addtocart.phtml add a button along with add to cart button.

<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/url') ?>')"><span><span><?php echo $this->__('Send as a Gift') ?></span></span></button>

Then add this script on this page itself:

 function setcheckoutLocation(location,chkout)
                     window.location.href = chkout;

This should work, I have tested it on Magento !! Good Luck

  • Glad to help. :)
    – Lalit838
    Sep 27, 2017 at 13:07
  • One more question , if you want and can help me, i'm trying to create a session variable if the this button was pressed. What i was trying to do was to make it looks like this : 'code'<?php session_start(); if (isset($_GET["sendasagift"])) { $_SESSION['variable']= "yes"; } else {$_SESSION['variable']="no";} ?>'code'
    – Opr
    Sep 28, 2017 at 12:43
  1. You have to rewritte in local : app>code>core>Mage>Checkout>controllers>CartController.php, clone addAction() in addcustomAction() then redirect to cart at the end in this new one addcustomAction() like this:

  2. Your new button should looks like this:

    <button type="button" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/addcustom', array('product'=>$_product->getId(), 'form_key' => Mage::getSingleton('core/session')->getFormKey())); ?>')"><?php echo $this->__('Send as a gift') ?></button>

Now your new button add a product to cart with redirecting to checkout/cart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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