Magento Add to Cart and Redirect to Checkout (product page: on “Checkout” button, “Add to Cart” redirects to cart)

checkoutmagentoproductredirect

I have two "Add to Cart" buttons on my product pages.

The first, default functionality, is just "Add to Cart", which functions as it should, adding the product to the cart, and redirects to the cart.

The second is labeled "Checkout" which I would like to have add the product to the cart, and redirect to checkout instead of the cart. (But only if the Checkout button was clicked).

I have looked, and it seems like an Observer might be used? I am not sure how to implement this, or differentiate which button was clicked, or what url to point the Checkout button to.

Best Answer

I think you can use jQuery for this.

Checkout Button in list.phtml

<button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

And add this script to same list.phtml file

<script>
function setcheckoutLocation(location)
{
jQuery.ajax({
                    type:"GET",
                    url:location,
                    success:function(data){
                         window.location.href = "http://your-checkout-page-url";
                    }
                 });

}
</script>
Related Topic