I have a Wordpress Woocommerce website with a hidden dropdown on my product page where I programmatically select an option from the dropdown when the page is loaded.
This function is working on my desktop in Google Chrome, Firefox and Microsoft Edge. It's also working on my Samsung phone in Google Chrome. For some reason, it's not working on my friends iPhone in the Safari browser.
$(document).ready(function() {
jQuery('.variations_form').on('wc_variation_form', function() {
if ($('select#account option').length > 0) {
var optionsInDropdown = 0;
console.log($('select#account option'));
$('select#account option').each(function() {
if ($(this).hasClass("attached enabled")) {
console.log($(this).val());
optionsInDropdown++;
}
});
console.log(optionsInDropdown);
if (optionsInDropdown > 1) {
$('select#account option').each(function() {
if ($(this).hasClass("attached enabled")) {
if ($(this).val() == "From scratch") {
return;
}
$(this).attr('selected', 'selected');
$('select#account').trigger("change");
console.log("Account " + $(this).val() + " geselecteerd");
return;
}
});
}
if (optionsInDropdown == 1) {
$('select#account option').each(function() {
if ($(this).hasClass("attached enabled")) {
$(this).attr('selected', 'selected');
$('select#account').trigger("change");
console.log("Account " + $(this).val() + " geselecteerd");
return;
}
});
}
}
});
});