🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Auto Select First Child Product of Magento 2 Configurable Product

By Sanjay JethvaUpdated on May 22, 2025 2 min read

However complex are the Magento 2 configurable products, there is no way out to sell complex products with multiple attributes!

But there are some ways out to make it simpler for particular cases. For example, you can implement the solution given here to auto-select the first child product of Magento 2 configurable product.

Doing so, you can show the first combination on the frontend. Also, attract customers and increase sales by always showing the first child product that is popular and tempting!

Moreover, if no options are chosen, a visitor might get confused with the options of the configurable product. By auto-selecting the first child product, it makes it easier for the visitors!

Other benefits are the minimized number of clicks for the visitors interested in the auto-selected combinations and improved customer experience!

Solution to auto select first child product of Magento 2 configurable product:

Override vendor\magento\module-swatches\view\frontend\web\js\swatch-renderer.js to your theme

Your theme file location is:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js

Locate change _RenderControls() function

Place the below code at the end of this function:

var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1){
    if($('.swatch-attribute').hasClass("size")){
        $('.swatch-option').first().trigger('click');
    }
}
meetanshi_How-to-Auto-Select-First-Child-Product-of-Magento-2-Configurable-Product

Implement the above solution and the task is done!

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.