0

I want to disable click on magento 2 color swatch but they are not working if one color is here i use this code in swatch-renderer.js file but they are not working

      // Connect Tooltip
        container
            .find('[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]')
            .SwatchRendererTooltip();

        // Hide all elements below more button
        $('.' + classes.moreButton).nextAll().hide();

        // Handle events like click or change
        $widget._EventListener();

        // Rewind options
        $widget._Rewind(container);

        //Emulate click on all swatches from Request
        $widget._EmulateSelected($.parseQuery());
        $widget._EmulateSelected($widget._getSelectedAttributes());

        
        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)
            }
        }
    },
0

You can disable options after click first item:

jQuery('.swatch-option.color').first().click();
jQuery('.swatch-option.color').prop('disabled',true)
4
  • this code is working in console panel but not working in my swatch-renderer.js file. – shohel hussain Sep 2 '20 at 7:54
  • you need to put after swatches was rendered – cnbandicoot Sep 2 '20 at 8:12
  • yes I added your code but code not working can you send me right place for this code – shohel hussain Sep 2 '20 at 11:12
  • update your question to add where are you adding your code. – cnbandicoot Sep 2 '20 at 11:14

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.