Customizing Magento Onepage Checkout Form
Hello Bertie,
Thank you for reaching out with your question about customizing the onepage checkout form in Magento 1.5.1.0. I’ll guide you through the process of removing the “fax” input field and moving the “region” dropdown below the “country” dropdown.
Understanding the Checkout Form Structure
The onepage checkout form is defined by several templates and blocks within your Magento installation. The main file responsible for this section is located at:
app/design/frontend/default/theme_package/template/checkout/onepage/form.phtml
This template includes various blocks, such as checkout.onepage.address.form for the address block.
Removing the “Fax” Input Field
To remove the “fax” input field from the onepage checkout form, you need to modify the form.phtml template. Open this file and locate the following code section:
<div class="field">
<label for="billing:fax"><?php echo $this->__('Fax'); ?></label>
<div class="input-box">
<input type="text" name="billing[fax]" id="billing_fax" value="<?php echo $addressData['fax']; ?>" title="<?php echo $this->__('Fax'); ?>" class="input-text validate-fax" />
</div>
</div>
Simply delete this entire <div class="field"> block to remove the “fax” field.
Moving the “Region” Dropdown Below the “Country” Dropdown
To move the “region” dropdown below the “country” dropdown, we need to modify two files: form.phtml and address.phtml.
- Modifying form.phtml
Open
form.phtmlagain and locate the section where the address block is rendered:
$block = $this->getChildHtml('checkout.onepage.address.form');
This line gets the child block “checkout.onepage.address.form” which contains the actual address field rendering. We need to modify this block next.
- Modifying address.phtml
Open
address.phtml, located at:
app/design/frontend/default/theme_package/template/checkout/onepage/address.phtml
Find the following code section, which renders the “region” and “country” fields:
<div class="field">
<label for="billing:region_id"><?php echo $this->__('Region'); ?></label>
<div class="input-box">
<?php echo Mage::getSingleton('adminhtml/system_config_source_country')->getSelectOptions(); ?>
</div>
</div>
<div class="field">
<label for="billing:country_id"><?php echo $this->__('Country'); ?></label>
<div class="input-box">
<?php echo Mage::getSingleton('adminhtml/system_config_source_country')->getSelectOptions(); ?>
</div>
</div>
Swap these two <div class="field"> blocks to get the desired order:
<div class="field">
<label for="billing:country_id"><?php echo $this->__('Country'); ?></label>
<div class="input-box">
<?php echo Mage::getSingleton('adminhtml/system_config_source_country')->getSelectOptions(); ?>
</div>
</div>
<div class="field">
<label for="billing:region_id"><?php echo $this->__('Region'); ?></label>
<div class="input-box">
<?php echo Mage::getSingleton('adminhtml/system_config_source_region')->getSelectOptions($countryId); ?>
</div>
</div>
Now, the “region” dropdown will appear below the “country” dropdown.
Conclusion
In this guide, we’ve learned how to customize the onepage checkout form in Magento by removing unnecessary fields and rearranging elements. This demonstrates the flexibility of Magento’s template system for modifying the frontend layout.
Remember that when working with Magento templates, it’s best practice to create a custom theme or use a child theme to avoid losing changes during updates. This ensures your modifications are kept intact even after updating your Magento installation.
For more detailed information on Magento theming and customization, I recommend checking out our comprehensive guide at Laravel Company.
Happy coding! Let me know if you have any further questions.
Best regards, [Your Name]