Skip to content

Instantly share code, notes, and snippets.

@dexit
Created November 19, 2019 23:30
Show Gist options
  • Save dexit/c04e5496c510bd7ccb16db91e8b3244c to your computer and use it in GitHub Desktop.
Save dexit/c04e5496c510bd7ccb16db91e8b3244c to your computer and use it in GitHub Desktop.
WooCommerce select first option on all single variation dropdowns
let selectFields = document.querySelectorAll(".wc-default-select");
selectFields.forEach( (item, index) => {
let itemLen = item.length;
// check length console.log(brand);
if (itemLen == 2){
// set index
item.selectedIndex = 1;
//console.log("selected");
}else{
console.log("died");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment