Magento – How to set default value in custom option in magento2

adminformcustom-optionsdefault valuesmagento2

I want to set default option to the custom options value in the product level.

How to do that in Magento 2 ?
enter image description here

Please help me to resolve on this.

Best Answer

I'm not sure you can do this via admin. I just did a work around where I made sure all my "default options" are the first option within admin then added the below to js for my store.

<script>
require(['jquery', 'jquery/ui'], function($){ 
  $('.product-add-form .field select').each(function(i, obj) {
    $(obj).find('option:eq(1)').prop('selected', true);
  });
});
</script>

This works for custom options as they are all rendered on page load. The code just loops through all custom options and sets the 2nd option as the first was "please select".

I had a bit more difficulty however with configurable products as the options were all loaded after page load but to do that too you can see my question here: Magento 2: How to set default option in configurable options?

Related Topic