0

I want to show currency symbol and amount in separate html elements such as: BD18.00

into this:

<span>BD</span><span>18.00</span>

is it achievable?

1
  • Heyy.. Did you get anything? Commented Aug 5, 2020 at 4:33

4 Answers 4

0
<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterfa‌​ce'); 
$currencyCode = $storeManager->getStore()->getCurrentCurrencyCode(); 
$currency = $objectManager->create('Magento\Directory\Model\CurrencyFact‌​ory')->create()->loa‌​d($currencyCode); 

echo "<span>{$currency->getCurrencySymbol()}</span><span>{$product->getPrice()}</span>"; 
?>
1
  • I can show in this way, but I want it to behave like default price like changing custom option, will change price as well.
    – Manish Joy
    Commented Nov 20, 2017 at 5:32
0

You can change the price format by change theme files.

\app\design\frontend\vendor\theme\Magento_Catalog\templates\product\price\amount\default.phtml

Just replace or comment

<?= /* @escapeNotVerified */ $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

and add the following snippet

<span class="av-new-price"><?= $block->getDisplayCurrencyCode() ?></span>
    <span class="av-amount"><?php echo number_format($block->getDisplayValue(),2) ?></span>

If this file not in your directory just overrides.

0

You can use below code to get the currency symbol and currency code in your template file:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface')->getStore();
$currencyCode = $storeManager->getCurrentCurrencyCode();
$currencyFactory = $objectManager->create('Magento\Directory\Model\CurrencyFactory');
$currency = $currencyFactory->create()->load($currencyCode);
$currencySymbol = $currency->getCurrencySymbol();
$productPrice = $_product->getPrice();
$productFinalPrice = $_product->getFinalPrice();
echo "<span class='cur-code'>".$currencyCode."</span>"; // prints currency code of your current store. E.g. 'USD' OR 'EUR' OR 'GBP' OR 'INR' etc..
echo "<span class='cur-symbol'>".$currencySymbol."</span>"; // prints currency symbol of your current store. E.g. '$' OR '€' OR '£' OR '₹' etc..
echo "<span class='prod-price'>".$productPrice."</span>";// prints product's price value.
echo "<span class='final-price'>".$productFinalPrice ."</span>";// prints value of product's final price.
?>

This is a tested code and will print the values as per your current store or as per the active currency switcher.

Hope this will help you! :)

0

try this below code

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$currencysymbol = $objectManager->get('Magento\Store\Model\StoreManagerInterface');

$currency = $currencysymbol->getStore()->getCurrentCurrency();

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.