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
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityplease follow the below link,
you need to change this as per your attribute,
it working fine for me
https://meetanshi.com/blog/auto-select-first-child-product-of-magento-2-configurable-product/
First, you need to override this file in your custom theme as below:-
app/design/frontend/Vendor/theme/Magento_Swatches/web/js/swatch-renderer.js
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){
if($('.swatch-attribute').hasClass("color")){
$('.swatch-option').first().trigger('click');
}
}
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 ...