2

In Magento 2 (Luma child theme) when enabling multiple currencies you get a currency switcher dropdown in the frontend's header.
By default, it shows the currency code followed by the full name,

e.g. GBP - British Pound Sterling.

I want to keep GBP, USD etc.
But remove the rest as I think it's unnecessary, customers can tell the currency from the code.
I am new to Magento 2 and can't find where in the template or layout files this can be changed.

Any idea?

  • Hello @webrightnow, Have you tried my solution ? – Pawan Mar 19 at 17:56
1

copy file:

mage2Root/vendor/magento/module-directory/view/frontend/templates/currency.phtml

to

app/design/frontend/{Package}/{theme}/Magento_Directory/templates/currency.phtml

After that you need to remove Currency code.

Code responsible for showing currency code is:

- <?= @$block->escapeHtml($currencies[$currentCurrencyCode]) ?>

Above code will remove active currency code. For other currency code you need to remove:

- <?= $block->escapeHtml($_name) ?>

from li

Before edit:

enter image description here

After Edit:

enter image description here

Hope above will help!

1

Original FIle path

vendor\magento\module-directory\view\frontend\templates\currency.phtml

Override file in your child theme and past below code

app\design\frontend\vendor\theme\Magento_Directory\templates\currency.phtml

<?php if ($block->getCurrencyCount() > 1): ?>
<?php $currencies = $block->getCurrencies(); ?>
<?php $currentCurrencyCode = $block->getCurrentCurrencyCode(); ?>
<?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : '' ?>
<div class="switcher currency switcher-currency" id="switcher-currency<?= $block->escapeHtmlAttr($id) ?>">
    <strong class="label switcher-label"><span><?= $block->escapeHtml(__('Currency')) ?></span></strong>
    <div class="actions dropdown options switcher-options">
        <div class="action toggle switcher-trigger"
             id="switcher-currency-trigger<?= $block->escapeHtmlAttr($id) ?>"
             data-mage-init='{"dropdown":{}}'
             data-toggle="dropdown"
             data-trigger-keypress-button="true">
            <strong class="language-<?= $block->escapeHtml($block->getCurrentCurrencyCode()) ?>">
                <span><?= $block->escapeHtml($currentCurrencyCode) ?></span>
            </strong>
        </div>
        <ul class="dropdown switcher-dropdown" data-target="dropdown">
            <?php foreach ($currencies as $_code => $_name): ?>
                <?php if ($_code != $currentCurrencyCode): ?>
                    <li class="currency-<?= $block->escapeHtmlAttr($_code) ?> switcher-option">
                        <a href="#" data-post='<?= /* @noEscape */ $block->getSwitchCurrencyPostData($_code) ?>'><?= $block->escapeHtml($_code) ?></a>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </div>
</div>
<?php endif; ?>

  • Thanks, that did it. Trust Magento to hide templates in directories where no newbie developer will ever think to look. "Module-directory"? How does that name in ANY way relate to currency? Why not "Module-currency"? Go figure... – webrightnow Mar 18 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.