How can I add a new text field in the custom options section in Magento 2 as shown in the screenshot below?



1 Answer 1


Answer: I got the answer for the above question to add the text field by simply editing the customOptions.php file

Location:vendor/magento/module- catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

step1: Add your text field at line number:68

const FIELD_NEW_TEXT_NAME = 'new_text_field';

step2:Add the Children at line number:584,634

static::FIELD_NEW_TEXT_NAME => $this->getNewTextFieldConfig(41),

step3:Copy the Total function code of getMaxCharactersFieldConfig and Create the function at line number:936

by following code:

protected function getNewTextFieldConfig($sortOrder)
    return [
        'arguments' => [
            'data' => [
                'config' => [
                    'label' => __('New Text field'),
                    'componentType' => Field::NAME,
                    'formElement' => Input::NAME,
                    'dataScope' => static::FIELD_NEW_TEXT_NAME,
                    'dataType' => Number::NAME,
                    'sortOrder' => $sortOrder,
                    'validation' => [
                        'validate-zero-or-greater' => true

step 4:Created the respected columns for fields in database find the table name below:

catalog_product_option catalog_product_option_type_value

Step 5:clear the cache and check the out put.

  • I'm not able to get the custom option from $block->getOption(); if any idea?
    – Mahi M
    Dec 21, 2018 at 12:03
  • While this may work, you really shouldn't edit core files. Jul 16, 2021 at 16:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.