Search code examples
magentomagento-1.9

How to show shipping costs per product in product page in Magento 1.9.1


Is there a way to show product costs in product detail page in Magento 1.9.1? I'd like for each product to display related shipping cost, really thanks


Solution

  • You can paste the following code into the ‘/template/catalog/product/view.phtml’ file in your theme.

    if($_product->isSaleable())
    {
    $quote = Mage::getModel('sales/quote');
    $quote->getShippingAddress()->setCountryId('DK');
    $quote->addProduct($_product); 
    $quote->getShippingAddress()->collectTotals();
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->getShippingAddress()->collectShippingRates();
    $rates = $quote->getShippingAddress()->getShippingRatesCollection();
    
    foreach ($rates as $rate)
    {
    echo $rate->getPrice();
    }
    }
    

    The last foreach will give you the shipping rates of different shipping methods enabled. Store it in any variable and display it where ever you want in the view.phtml file. You are done!