Where can I the html select tag for countries on the checkout page?

<div class="field form-group">
       <label for="billing:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
       <div class="input-box">
          <?php echo $this->getCountryHtmlSelect('billing') ?>

with this $this->getCountryHtmlSelect('billing'), it returns the html select tag below,

<select name="billing[country_id]" id="billing:country_id" class="validate-select" title="Country" >
<option value="" > </option>
<option value="AF" >Afghanistan</option><option value="AL" >Albania</option>
<option value="DZ" >Algeria</option>

But I need to add a class name to the select tag,

class="form-control validate-select"

But where can I find this select tag?


The country select box is prepared by the block,

To change its behavior you just need override the function to you local folder like below.

Just copy the core\Mage\Checkout\Block\Onepage\Billing.php to you local folder like


Now you just need to put the below code in that file see I have added the "form-control" to setClass() function.

its done now your class will be added to the select box.

public function getCountryHtmlSelect($type)
    $countryId = $this->getAddress()->getCountryId();
    if (is_null($countryId)) {
        $countryId = Mage::helper('core')->getDefaultCountry();
    $select = $this->getLayout()->createBlock('core/html_select')
        ->setClass('validate-select form-control')
    if ($type === 'shipping') {

    return $select->getHtml();

Almost the same as your other question: How to set default shipping method and country?

Try replacing:

<?php echo $this->getCountryHtmlSelect('billing') ?>

With this:

<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadByStore()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
    <select name="billing[country_id]" id="billing:country_id" class="validate-select">
        <option value="">Please choose a country...</option>
        <?php foreach($_countries as $_country): ?>
            <option value="<?php echo $_country['value'] ?>">
                <?php echo $_country['label'] ?>
        <?php endforeach; ?>
<?php endif; ?>

Then all you need to do is add classes to <select name="billing[country_id]" id="billing:country_id" class="validate-select">

  • Worked perfectly - no need to overwrite core files or create new - spot on! – Simon Jan 27 '15 at 8:48

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.