I am using Magento 2.2.5

I need to hide a text attribute which I'm using to save serialized data of custom options of product.

Edit Product in magento backend

I think this can be done using adminhtml/ui_component/product_form.xml file, but don't know how.

Thanks

You can try below steps to hide product fields

Step 1:

create catalog_product_edit.xml under app/code/Vendor/Module/view/adminhtml/layout

File : catalog_product_edit.xml

<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="myattribHide" before="before.body.end" template="Vendor_Module::product/edit/fieldhide.phtml" />
</referenceContainer>  

Step 2: Create file fieldhide.phtml under app/code/Vendor/Module/view/adminhtml/templates/product/edit

File : fieldhide.phtml

<script>
    require([
        'jquery',
        'uiRegistry'
    ], function($,uiRegistry){
        uiRegistry.get("product_form.product_form.content.container_yourcustomfield.yourcustomfield", function (element) {
         element.hide();
      });        
    })
</script>

Note : Please replace "yourcustomfield" with your attribute code

Step 3: Please remove static files and refresh cache

  • Thank you for your answer, I'll try this and update you regarding its result. – Knight017 Dec 11 at 8:34
  • @Knight017 Thank you. – Pritam Info 24 Dec 11 at 9:26
  • I have tried your way but unable to have the desired result, I have done and cleared cache like rm -rf pub/static/* var/di/* var/cache/* var/page_cache/* generated/* var/view_preprocessed/* && php -dmemory_limit=6G bin/magento setup:upgrade && php -dmemory_limit=6G bin/magento setup:static-content:deploy -f – Knight017 Dec 11 at 9:35
  • can you please confirm JS is working or not . Also make sure you replace yourcustomfield.yourcustomfield with your field id. For that please right click and use View Source tool of your browser. – Pritam Info 24 Dec 11 at 9:41
  • I have checked the file does not called at all. I have add console.log() after first line of script tag. – Knight017 Dec 11 at 9:53

I have added below line in my install script to not display the attribute in product edit page in admin.

$installer->updateAttribute('catalog_product', $attribute_code, 'is_visible', '0');

I have found the Hide Attributes and Other Fields in Product Edit Backend reference from an older question.

CAUTION :: With this approach, I'm not able to display saved serialized data in fields.

This question is related with my other question in which I have mentioned how to save product's custom options in serialized form in attribute How to save serialized data in product's text backend_type custom attribute.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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