1

How to add two custom fields for all payment methods in my payment section of magento 2,Can any one help me on this?

$jsLayout['components']['checkout']['children']['steps']['children']['payment']['children']
        ['methods']['children']['paymentAdditional'] = [
            'component' => 'uiComponent',
            'displayArea' => 'paymentAdditional',
            'children' => [
                'delivery_date' => [
                    'component' => Vendor_Module/js/view/payment/method-renderer/taxInfo-comp',
                    'config' => [
                        'customScope' => 'methods',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'vendor_module/payment/taxinfo-form',
                        'options' => [],
                    ],
                    'dataScope' => 'methods.tax_code',
                    'label' => 'Tax Code',
                    'provider' => 'checkoutProvider',
                    'visible' => true,
                    'validation' => false, //['required-entry' => $this->_helper->getConfigIsFieldRequired()],
                    'sortOrder' => 200,
                ]
            ],
        ];
3
1

If You want two add new custom field for all payment method in payment section of magento 2

you can overwrite \Magento\Checkout\Block\Checkout\LayoutProcessor

follow this sequence

/[vendor]/[module]/etc/frontend/di.xml

<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="checkout_custom_fields" type="vendor\module\Plugin\Checkout\LayoutProcessor" sortOrder="100"/>
    </type>

vandor/module/Model/Checkout/LayoutProcessorPlugin.php

namespace vendor\module\Model\Checkout;

class LayoutProcessorPlugin
{

    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */

    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
        array  $jsLayout
    ) {
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['delivery_date'] = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/date',
                'options' => [],
            ],
            'dataScope' => 'shippingAddress.your_field',
            'label' => 'field label',
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' => [],
            'sortOrder' => 200
        ];
        return $jsLayout;
    }
}

Reference here

5
  • 1
    The above code is for shipping method.in payment section not working.i have already tried.and the path is incorrect it should be \Magento\Checkout\Model\Checkout\LayoutProcessor
    – rajat kara
    Nov 21 '16 at 13:10
  • can you please upload screen short where you need add costume field.
    – user44966
    Nov 21 '16 at 13:12
  • Please check the code in my question.
    – rajat kara
    Nov 21 '16 at 13:17
  • You can follow [Reference link] below at my answer. This is working .
    – user44966
    Nov 21 '16 at 13:20
  • I have already checked in payment method,not working but in shipping method its working.
    – rajat kara
    Nov 21 '16 at 13:22

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.