Re: How can I auto-select the first one that available?

Solved

How can I auto-select the first one that available?

thaxpy
Tourist
11 0 2

Pic2.png

 

Pic2.png

 

As you can see when I select variant 30.5g, The size variant 6" of 30.5g should be auto select, isn't it? but it is not. (Dawn theme)

How can I fix this?

Accepted Solution (1)
ThePrimeWeb
Shopify Partner
2139 616 529

This is an accepted solution.

Hey @thaxpy,

 

Go to your theme's "Edit Code" Option, then in the search bar type "theme.liquid".
Scroll to the end and above the tag "</body>" tag paste the following. Screenshot attached for reference.

<script>
document.addEventListener('DOMContentLoaded', function () {
    let weights = document.querySelectorAll('input[name="Weight"]');

    weights.forEach(function(value, index){
        value.addEventListener('click', function() {
            setTimeout(() =>{
                let size = document.querySelectorAll('input[name="Size"]:not(.disabled)');
                size[0].click();
                found = true;    
            },100);
        });
    });
});
</script>

 

Screenshot for reference.

ThePrimeWeb_0-1710690294131.png

 

Was I helpful?

Buy me a coffee

🙂

Need help with your store? contact@theprimeweb.com or check out the website
Check out our interview with Shopify!

View solution in original post

Replies 5 (5)

ThePrimeWeb
Shopify Partner
2139 616 529

Hey @thaxpy,

 

Can you share the link to your store? Thanks!

Was I helpful?

Buy me a coffee

🙂

Need help with your store? contact@theprimeweb.com or check out the website
Check out our interview with Shopify!
ThePrimeWeb
Shopify Partner
2139 616 529

This is an accepted solution.

Hey @thaxpy,

 

Go to your theme's "Edit Code" Option, then in the search bar type "theme.liquid".
Scroll to the end and above the tag "</body>" tag paste the following. Screenshot attached for reference.

<script>
document.addEventListener('DOMContentLoaded', function () {
    let weights = document.querySelectorAll('input[name="Weight"]');

    weights.forEach(function(value, index){
        value.addEventListener('click', function() {
            setTimeout(() =>{
                let size = document.querySelectorAll('input[name="Size"]:not(.disabled)');
                size[0].click();
                found = true;    
            },100);
        });
    });
});
</script>

 

Screenshot for reference.

ThePrimeWeb_0-1710690294131.png

 

Was I helpful?

Buy me a coffee

🙂

Need help with your store? contact@theprimeweb.com or check out the website
Check out our interview with Shopify!
thaxpy
Tourist
11 0 2

It really works, thank you! 

EdRaga
Visitor
2 0 0

Hello, thanks for the code but I want to tell you that it works in some versions of Dawn, but not in all, do you know how to solve it?