Show Custom Customer Fields in Checkout

Show Custom Customer Fields in Checkout

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Show Custom Customer Fields in Checkout

Displaying Custom Customer Fields in Onepage Checkout

As an experienced developer, I understand your frustration when custom customer fields don’t behave as expected in the checkout process of your Magento store. Let’s dive into the issue and find a solution step-by-step.

Understanding the Problem

You’ve successfully added a new attribute (lastname2) to the customer entity, and it works perfectly in the admin section and the standard registration form. However, when you try to display this field in the onepage checkout form, it appears but seems to have the wrong value or no label associated with it.

The Underlying Issue

The problem lies in how Magento handles attribute visibility. When you set ‘visible’ to true for an attribute, it’s added to the customer entity and can be seen in the admin section. However, this doesn’t guarantee that the attribute will be processed by the form controllers used in checkout or registration.

To ensure your custom field appears correctly during checkout, you need to specifically include it in the ‘used_in_forms’ array for each controller where you want to display it. Currently, you’ve only included it in the admin_form and standard registration form.

The Solution

Here’s how you can modify your attribute installation code to ensure the lastname2 field appears correctly during checkout:

$installer->startSetup();
$attributes = array(
    'lastname2' => array(
        //... existing configuration ...
        'used_in_forms' => array('adminhtml_customer', 'customer_account_edit', 'checkout_register', 'customer_account_create', 'sales_order_create'),
    ),
);
foreach($attributes as $attribute_code=>$definition)
{
    //... rest of the code ...
}
$installer->endSetup();

In this updated code, I’ve added the controller sales_order_create to the used_in_forms array. This tells Magento to include the lastname2 field in the onepage checkout form.

Updating the Checkout Form

Next, you need to ensure that your custom field appears in the checkout.phtml file. Look for the section where customer information is displayed and add a new div block for your custom field:

<div class="field name-lastname2">
    <label for="lastname2" class="required"><em>*</em>Apellido Materno</label>
    <div class="input-box">
        <input type="text" id="lastname2" name="lastname2"
               value="<?php echo $this->escapeHtml($this->getCustomer()->getLastname2()) ?>"
               title="Apellido Materno" maxlength="255"
               class="input-text validate-length-maximum-lastname2"
               data-validate="{&quot;maxlength&quot;: &quot;255&quot;, &quot;required&quot;: true}"
               />
    </div>
</div>

This code adds a new input field for lastname2 with the appropriate label and validation rules. It uses the $this->getCustomer()->getLastname2() method to fetch the value of your custom attribute.

Conclusion

Remember, when working with custom customer attributes in Magento, you need to ensure they are correctly configured for each form where you want them to appear. By updating the used_in_forms array and the checkout.phtml file, you should now see your custom field displayed accurately during onepage checkout.

Don’t forget that after making these changes, you’ll need to reinstall or update your theme to ensure they take effect in your frontend. If you encounter any further issues or need more assistance with Magento development, feel free to reach out!

For professional Magento services and expert advice on optimization and customization, visit Laravel Company.

Checkout Admin Configuration Customers

Our network