Jump to content

Set default variant?

Go to solution Solved by SpencerC,

Recommended Posts

  • 10 months later...
  • 3 months later...
On 8/12/2019 at 10:48 PM, LagoVistaFilmLab said:

I would love to set the default variant

You can set the default variant on each product using our Variant Pricing extension.

variant-pricing-tile.thumb.png.a2c98ef27e29d4a50e3183ff16f5f031.png

Our extension preselects the first option in every variant dropdown so that customers can quickly purchase the default variant. Do contact me if you have questions or want to purchase something more bespoke.

-Paul

About me: I'm Paul, a SQSP user for over 18 yrs and a Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL, providing high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji below. Buying a coffee is optional.

Book paid help with domains: Connect a GoDaddy domain. Connect a Squarespace Domain. Domain assistance

Link to comment
  • 2 years later...

You don't need to pay for an app: use this code

<script>

function setValue() 
  
{
     var dropdown = document.querySelectorAll('[data-variant-option-name="Type"]')[0];
    dropdown.value = 'Summer Flap';
    Y.one(dropdown).simulate('change');
  
  var dropdown2 = document.querySelectorAll('[data-variant-option-name="Colour"]')[0];
    dropdown2.value = 'Orange $89';
    Y.one(dropdown).simulate('change');
  
}
  
  window.onload = setValue;

</script>

Link to comment
  • 1 month later...
<script>
function setValue() {
document.querySelectorAll('div.variant-option select').forEach(function(dropdown){
  dropdown.selectedIndex = '1';
  Y.one(dropdown).simulate('change');
});
}
 window.onload = setValue ;
</script>

The above code can put in `Page Header Code Injection` and it will select the first variant option and displays its price as well

I modified @DomBrady answer to work with any product variant without having to specify variant details in code

Edited by AshAb
Link to comment
  • 5 months later...
On 8/8/2023 at 6:28 AM, AshAb said:
<script>
function setValue() {
document.querySelectorAll('div.variant-option select').forEach(function(dropdown){
  dropdown.selectedIndex = '1';
  Y.one(dropdown).simulate('change');
});
}
 window.onload = setValue ;
</script>

The above code can put in `Page Header Code Injection` and it will select the first variant option and displays its price as well

I modified @DomBrady answer to work with any product variant without having to specify variant details in code

Thanks for this!! 🙌🏼

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.