Here are some good ways to call the price part of a product in Magento. Please make proper use of the parts in the code below to add to your block’s class
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
\Magento\Store\Model\StoreManagerInterface $_storeManager,
...............
$this->_storeManager = $_storeManager;
......................
public function getCurrencySymbol() {
return $this ->_storeManager->getStore()->getBaseCurrency()->getCurrencySymbol();
}
/**
* @param \Magento\Catalog\Model\Product $product
* @return string
*/
public function getProductPrice(\Magento\Catalog\Model\Product $product)
{
$priceRender = $this->getPriceRender();
$price = '';
if ($priceRender) {
$price = $priceRender->render(
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
$product,
[
'include_container' => true,
'display_minimal_price' => true,
'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
'list_category_page' => true
]
);
}
return $price;
}
protected function getPriceRender()
{
return $this->getLayout()->getBlock('product.price.render.default')
->setData('is_product_list', true);
}
then use these calls to get the correct product price and currency symbol . in file .phtml
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
<?= $block->getCurrencySymbol().number_format($product->getFinalPrice(), 2); ?>
//or
<?= $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($product->getFinalPrice(), true, false); ?>
//or
<?= $block->getProductPrice($product); ?>