Magento: Get Add to Cart URL of any Product

Here is a quick code to get add to cart url of any product.

Suppose that we are fetching add to cart url of a product with id ‘166’.


$_productId = '166';
$_product = Mage::getModel('catalog/product')->load($_productId);
$_url = Mage::helper('checkout/cart')->getAddUrl($_product);

Hope it helps. Thanks.