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

1 Answer 1

4

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!

4
  • Works fine here, on Magento CE 1.9.3.6.
    – Anse
    Commented Sep 22, 2017 at 8:33
  • 1
    Just one glitch, as not everyone lives in Denmark: $quote->getShippingAddress()->setCountryId(Mage::getStoreConfig('general/country/default'));
    – Anse
    Commented Sep 22, 2017 at 8:46
  • I've successfully used this option for several years in Magento1 but I've changed to Magento2. How to achieve to show shipping-costs per product in product-page on Magento2
    – Peter
    Commented Apr 5, 2020 at 10:44
  • It's not working for me at magento 1.9.4.4. I can debug until $quote->getShippingAddress()->collectTotals(); after it not works. someone can help me? Commented May 24, 2021 at 18:42

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.