0

I'm trying to have swatch option values selected on the Product View page if only one value exists.

also, I have tried this reference but not working for me https://magento.stackexchange.com/a/176243/68695

like :

enter image description here

Note: when one swatch value available then this value is auto selected and remove validation message

1

i have solved following way..

open below file if exist otherwise overide

app/design/frontend/Vendor/theme/Magento_Swatches/web/js/swatch-renderer.js

Make changes in the _RenderControls() function as shown below.

after end of this function add like this code

var swatchLength = $('.swatch-option.color').length; // if color attribute 
  if(swatchLength == 1){
     if($('.swatch-attribute').hasClass("color")){
        $('.swatch-option').first().trigger('click');
      }
  }

enter image description here

after run below command

php bin/magento setup:static-content:deploy -f 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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