如何在 Magento 1.9.1 的产品页面中显示每个产品的运费

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

有没有办法在 Magento 1.9.1 的产品详细信息页面中显示产品成本? 我希望每个产品都显示相关的运费,非常感谢

您可以将以下代码粘贴到主题中的“/template/catalog/product/view.phtml”文件中。

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();
}
}

最后一个 foreach 将为您提供启用的不同运输方式的运费。将它存储在任何变量中,并在 view.phtml 文件中的任意位置显示它。你完成了!