0

I followed the first steps of this documentation (https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html) to add a new input field (date of birth) to the shipping address form in checkout. Here is my relevant code in a plugin class:

    <?php

namespace Vendor\Module\Plugin;

use Vendor\Module\Helper\Data;

class AddDob
{

    private $_helper;


    function __construct(
        Data $helper
    )
    {
        $this->_helper = $helper;
    }


    public function afterProcess($subject, $jsLayout)
    {
        if (!$this->_helper->isEnabled()) return $jsLayout;

        $customAttributeCode = 'dob';

        $customField = [
            'component' => 'Vendor_Module/js/form/element/dob',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'Vendor_Module/form/element/dob'
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$customAttributeCode,
            'label' => __('Date of birth'),
            'provider' => 'checkoutProvider',
            'sortOrder' => $this->_helper->getSortOrder(),
            'options' => [],
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
        ];

        if ($this->_helper->isRequired()) {
            $customField['validation']['required-entry'] = true;
        }

        if ($this->_helper->tooltipIsEnabled()) {
            $customField['config']['tooltip'] = [
                'description' => $this->_helper->tooltipGetContent()
            ];
        }

        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$customAttributeCode] = $customField;

        return $jsLayout;
    }
}

I also implemented the plugin class via di.xml. So it works basically as you can see here: enter image description here

However when I proceed to the billing form, I see two new rows in the address, one says "dob" (which is the name of my date of birth input field) and the other one displays its value, as you can see here: enter image description here

But I do not want them to appear in the address. How can I get rid of it?

0

If you open the following file:

vendor/magento/module-checkout/view/frontend/web/template/billing-address/details.html

Following code is responsible for rendering custom attributes

<each args="data: currentBillingAddress().customAttributes, as: 'element'">
    <each args="data: Object.keys(element), as: 'attribute'">
        <if args="typeof element[attribute] === 'object'">
            <if args="element[attribute].label">
                <text args="element[attribute].label"/>
            </if>
            <ifnot args="element[attribute].label">
                <if args="element[attribute].value">
                    <text args="element[attribute].value"/>
                </if>
            </ifnot>
        </if>
        <if args="typeof element[attribute] === 'string'">
            <text args="element[attribute]"/>
        </if><br/>
    </each>
</each>

So overwrite this template and remove this code section.

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.