Can anyone let me know that in the configurable product dropdown attribute have only one option available so it should be auto select ?

enter image description here

In the screenshot you can see that only A is available so after selection of other attribute it should auto select.

  • this is not the solution, I have to auto select if have only one option available. The above link is by default first option will be selected. Aug 17, 2020 at 11:47
  • 1
    if you have only one option then why are you making configurable product ?just a curiosity
    – Pramod
    Aug 17, 2020 at 11:50
  • there is 4 to 5 attribute, and after selection of other attribute this need to be auto select. I think you are not getting my question. Aug 17, 2020 at 11:56

1 Answer 1


Maybe try replacing

if (i == 0) {this.options.values[attributeId] = options[i].id;}  


if (options.length == 1 ) {this.options.values[attributeId] = options[i].id;} 


just before the end of for loop as explained in this example.

Note: In my case, configurable products are only with selectable dropdown and with these as options

Colors and Sizes, few of the colors have only one option like black. So, the above code works well by pre-selecting if the Colors options have only one option.

Your Answer

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

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