Magento - Adding a new field for shipping address during onepage checkout process

Magento - Adding a new field for shipping address during onepage checkout process

September 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Adding a new field for shipping address during onepage checkout process

Adding a New Field for Shipping Address During Magento Onepage Checkout

If you’re looking to add a new field like “custom_house_no” specifically for the shipping address during the onepage checkout process in your Magento store, here’s a comprehensive guide on how to achieve this:

Step 1: Add the New Attribute in the Install Script

The first step is to create and add the new attribute using an install script. In your custom extension’s mysql4-install-0.1.0.php file, you would include the following code:

// Customer Address
$entityTypeId     = $installer->getEntityTypeId('customer_address');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute('customer_address', 'custom_house_no', array(
    // Attribute configurations here...
));

// Add the attribute to a group
$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'custom_house_no',
    '150'       // last Magento's attribute position in General tab is 140
);

// Set the relation between the attribute and forms it should be used in
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'custom_house_no');
$attribute->setData('used_in_forms', array('customer_register_address', 'customer_address_edit', 'adminhtml_customer_address'));
$attribute->save();

Make sure to replace the // Attribute configurations here... comment with your actual attribute configurations, such as label, input type (text in this case), data types, and other necessary settings.

Step 2: Create a Custom Entity Setup Class

Next, create a custom entity setup class under MY/CustomExtension/Model/Entity/Setup.php:

class MY_CustomExtension_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup {
}

Step 3: Update the Extension Configuration File

Update your extension’s configuration file to include the setup model:

<global>
    <models>
        <customextension>
            <class>MYPackage_CustomExtension_Model</class>
            <resourceModel>mypackage_customextension_resource</resourceModel>
            <entitiesBeforeSave>
                <customer_address>MY_CustomExtension_Model_Entity_Setup</customer_address>
            </entitiesBeforeSave>
        </customextension>
    </models>
</global>

Step 4: Update the Shipping Template File

Finally, update your shipping template file (usually located under template/onepage/checkout/success.phtml) to include a textbox field for “custom_house_no”:

<div class="field">
    <label for="custom_house_no">Custom House No:</label>
    <div class="input-box">
        <input type="text" name="custom_house_no" id="custom_house_no" value="" />
    </div>
</div>

Step 5: Test the Configuration

After updating your code, clear the cache and test the checkout process. The new “Custom House No” field should appear in the shipping address section during onepage checkout.

Remember to follow Magento’s best practices when developing extensions:

  1. Always use the correct entity type for customer-related attributes.
  2. Set user_defined to 1 if you want the attribute to be available in the admin panel.
  3. Use used_in_forms to specify which forms should include this attribute.

By following these steps and carefully configuring your custom extension, you can successfully add a new field for shipping addresses during onepage checkout in Magento.

For more information on Magento 2 development best practices and resources, visit https://laravelcompany.com/magento-development-resources.

Checkout Database Extensions Admin

Our network