Magento 2.3.2 Single color variation auto selected on product list page, i have added this code in swatch-render.js after container append but it is selecting on all products instead of selecting only visible products so if you have 500 to 600 products in this category then it will trigger this action 500 or 600 products instead of 18 which are currently visible.

$('.product-items .product-item:visible').each(function () {
                    // console.log("item count ",$('.product-items .product-item:visible').length);
                        var index = $(this).index();
                        var itemcount=$(this).length;
                        var text = $(this).find('.swatch-attribute.color').find('.swatch-attribute-options').children().length;
                        if(text==2) {

1 Answer 1


use This Code in your swatch-renderer.js var swatchLength = $('.swatch-option.color').length; // if color attribute if(swatchLength == 1){ if($('.swatch-attribute').hasClass("color")){ $('.swatch-option.color').first().click(); $('.swatch-option.color').prop('disabled',true); } }

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.