Toggle Nav
My Cart 0

Magento 2 first option auto selected on configurable drop down

Magento 2 first option auto selected on configurable drop down

Add below code to second _init: function () of "swatch-renderer.js" file (Location: /vendor/magento/module-swatches/view/frontend/web/js)


            if (this.options.jsonConfig.attributes.length > 0) {
                var selectswatch = this.element.find('.' + this.options.classes.attributeClass + ' .' + this.options.classes.attributeOptionsWrapper);
                $.each(selectswatch, function (index, item) {
                    var swatchOption = $(item).find('div.swatch-option').first();
                    if (swatchOption.length && !$(item).find('div.swatch-option').hasClass('selected')) {
                        swatchOption.trigger('click');
                    }
                });
            }

NOTE: Move this JS first to your current theme then update it.
June 14, 2018
Did you like this post?
0
0