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,
 ]
 ],
 ];
asked Nov 21, 2016 at 11:44
3
  • 1
    Please elaborate your requirements by for which purpose you need those custom fields? This thread may help you link Commented Nov 21, 2016 at 12:39
  • i want to add tax related information for all payment methods.please check this link magentocommerce.com/magento-connect/sales-tax-exempt.html Commented Nov 21, 2016 at 12:42
  • Am not aware of Magento 2,but for magento 1.9 versions you can make use of these link Commented Nov 21, 2016 at 13:04

1 Answer 1

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

answered Nov 21, 2016 at 12:54
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 Commented Nov 21, 2016 at 13:10
  • can you please upload screen short where you need add costume field. Commented Nov 21, 2016 at 13:12
  • Please check the code in my question. Commented Nov 21, 2016 at 13:17
  • You can follow [Reference link] below at my answer. This is working . Commented Nov 21, 2016 at 13:20
  • I have already checked in payment method,not working but in shipping method its working. Commented Nov 21, 2016 at 13:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.