Magento 2 get current store currency code [duplicate]
-
08-04-2021 - |
Question
In Magento 2 I have tried to get the current store code by the below-mentioned code line. But it returns an empty string.
$this->_storeManager->getStore()->getBaseCurrencyCode();
Solution
You can try with following code,
$this->_storeManager->getStore()->getCurrentCurrency()->getCode()
(Or)
public function __construct(
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
) {
$this->_priceCurrency = $priceCurrency;
}
public function getCurrentCurrencyCode()
{
return $this->_priceCurrency->getCurrency()->getCurrencyCode();
}
And call this function from your template,
echo $block->getCurrentCurrencyCode();
OTHER TIPS
To get store code:
$this->_storeManager->getStore()->getCode();
After your question update, to get current currency code
$this->_storeManager->getStore()->getCurrentCurrency()->getCode(); //EUR
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange