Magento Code: Include currency switcher in the header or footer with Foundation mark-up

Posted in Magento on 4 May 2017

This post has been archived

The content of this post has not been updated since 2015, and may be out of date. Extra care should be taken with any code provided.

It is easy to set-up multi-currencies in Magento. This code  allows you to quickly include a currency drop down or link to  the header or footer of your Magento store. Before you begin make sure you have enabled more than one currency  as this example won’t work without at least one additional currency alongside your base currency.

Set-up the following code in your theme directory. I’ve included code for both a drop down select box, or inline list of hyperlinks.

/app/design/frontend/package/theme/template/currency/currency.phtml

Display as a select drop-down

<?php if($this->getCurrencyCount() > 1): ?>
<div class="currency input-group">
   <label class="input-group-label" for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
   <select class="input-group-field" onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
   <?php foreach ($this->getCurrencies() as $iso => $name): ?>
      <option value="<?php echo $this->getSwitchCurrencyUrl($iso)?>" <?php if($iso == $this->getCurrentCurrencyCode()): ?>selected <?php endif; ?>>
         <?php echo $iso ?> - <?php echo $name ?>
      </option>
   <?php endforeach; ?>
   </select>
   </div>
<?php endif; ?>
<?php if($this->getCurrencyCount() > 1): $count = 0; ?>
<ul class="inline-list">
   <?php foreach ($this->getCurrencies() as $iso => $name): ?>
      <li>
         <?php if($iso == $this->getCurrentCurrencyCode()): ?>
            <strong><?php echo $iso ?></strong>
         <?php else: ?>
            <a href="<?php echo $this->getSwitchCurrencyUrl($iso)?>" ><?php echo $iso ?></a>
         <?php endif; ?>
      </li>
      <?php $count++; if ( $this->getCurrencyCount() > $count ) { echo " <li>/</li>"; } ?>
   <?php endforeach; ?>
</ul>
<?php endif; ?>

Then include the following in your /app/design/layout/local.xml. The reference tag can be changed from header to footer depending on where you want to include the currency switcher on the page.

<?xml version="1.0"?>
<layout version="0.1.0">
   <default>
      <reference name="header">
         <block type="directory/currency" name="custom_currency_selector" template="currency/currency.phtml"/>
      </reference>
   </default>
</layout>

The final step is to include the block in either header.phtml or footer.phtml as outlined above.

<?php echo $this->getChildHtml('custom_currency_selector') ?>

Related Magento Posts

October 2023

Magento database structure

The database structure of Magento is designed to store and manage various aspects of an e-commerce website, including products, orders, customers, and more. Understanding the...

Continue reading

August 2023

Accessibility in ecommerce websites

In the digital age, where online shopping has become an integral part of our lives, ecommerce websites hold the key to business success. Amidst the...

Continue reading

August 2023

Using Magento to get small businesses online

For small businesses aiming to establish a formidable online presence and drive sales, Magento emerges as a powerful e-commerce platform offering a suite of features...

Continue reading

July 2023

How can I speed-up my Magento website?

Speed optimisation is crucial for a Magento website as it directly impacts user experience, conversions, and search engine rankings. You should prepare your server so...

Continue reading

June 2023

.htaccess: Enable GZIP Compression for Magento

Enable Gzip compression on your server to compress your website's files before sending them to the visitor's browser. This significantly reduces the file size, resulting...

Continue reading

April 2023

Popular Payment Gateways

Ecommerce payment gateways are critical components of any online store, as they enable merchants to accept payments from customers securely and conveniently. There are many...

Continue reading

More Magento Posts