Hi I want whenever someone opens configurable product page with size and color the first child should be preselected

how to achieve this I am using latest Magento 2 version

2 Answers 2


please follow the below link,
you need to change this as per your attribute,
it working fine for me


  • already tried this not working
    – NsVentures
    Jul 2, 2020 at 15:29

First, you need to override this file in your custom theme as below:-


Change _RenderControls() function

After the end of this function add the below code:

var swatchLength = $('.swatch-option.color').length; // if color attribute 
  if(swatchLength == 1){

And then you need to run below command:-

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

Also, you can get more information here:-

https://magento.stackexchange.com/a/278663/85907 https://magento.stackexchange.com/a/129887/85907

Hope this helps you

Thanks ...

  • I am using size attribute as dropdown and this code is not working help
    – NsVentures
    Jul 4, 2020 at 23:46

Your Answer

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

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