Tuesday, September 20, 2011

Add a custom "add to cart" button on Magento CMS pages

Sometimes you'll want to show your products or introduce it on a CMS page for some reason. If you want to do that it's actually not so complicated, in your cms page editor, just add the following HTML code where you want it to appear in the page.
<button onclick="location.href ='{{config path="web/unsecure/base_url"}}/checkout/cart/add?product=1&qty=1′">Buy It Now</button> 
Save the page and refresh the cache. Now if you open the page in you should be able to see "Buy It Now" button. When clicked it adds 1 product with ID=1 to your shopping cart.
To make it a little more advanced, you can add the quantity of products you want to let the customers add, in that case use this code (example for five products).
<button onclick="location.href ='{{config path="web/unsecure/base_url"}}/checkout/cart/add?product=1&qty=5'">Buy 4 Get 1 Free</button> 

No comments:

Post a Comment