Last active
October 8, 2019 18:48
-
-
Save aatronco/f2c9554fa96c012292ea6374c4ecb8dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Fields that can be marked as optional in Settings > Checkout */ | |
function justHide(field) { | |
$("#billing_address_" + field).hide(); | |
} | |
$(document).ready(function() { | |
// Postal Code | |
justHide("postal"); | |
// Municipality | |
justHide("municipality"); | |
}); | |
/* Mandatory fields that require simple autocomplete and hide */ | |
function autoHide(field) { | |
$("#order_billing_address_" + field).val("Autocompleted " + field); | |
$("#billing_address_" + field).hide(); | |
} | |
$(document).ready(function() { | |
// Name | |
autoHide("name"); | |
// Surname | |
autoHide("surname"); | |
// Full Street Address | |
autoHide("address"); | |
// City | |
autoHide("city"); | |
}); | |
/* Special Cases: Country and Regions need to wait for the list to load before autocompleting */ | |
// Selects and hides the Country | |
country_selected = false | |
function selectHideCountry() { | |
$("#billing_address_country").hide() | |
var interval_c = setInterval(function() { | |
if ($("#order_billing_address_country").val() == "") { | |
$("#order_billing_address_country option:last").attr("selected", "selected"); | |
var sortBySelect = document.querySelector("#order_billing_address_country"); | |
sortBySelect.dispatchEvent(new Event("change")); | |
} else { | |
clearInterval(interval_c) | |
country_selected = true | |
} | |
}, 500); | |
} | |
// Selects and hides the Region | |
region_selected = false | |
function selectHideRegion() { | |
$("#billing_address_region").hide() | |
var interval_r = setInterval(function() { | |
if ($("#order_billing_address_region").val() == "" && country_selected) { | |
$("#order_billing_address_region option:last").attr("selected", "selected"); | |
} else { | |
clearInterval(interval_r) | |
region_selected = true | |
} | |
}, 500); | |
} | |
$(document).ready(function() { | |
selectHideCountry() | |
selectHideRegion() | |
}); | |
// Optional hides all (Don't use this if you didn't use the previous functions) | |
$(document).ready(function() { | |
$("#billing_address").hide(); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Fields that can be marked as optional in Settings > Checkout */ | |
function justHide(field) { | |
$("#shipping_address_" + field).hide(); | |
} | |
$(document).ready(function() { | |
// Postal Code | |
justHide("postal"); | |
// Municipality | |
justHide("municipality"); | |
}); | |
/* Mandatory fields that require simple autocomplete and hide */ | |
function autoHide(field) { | |
$("#order_shipping_address_" + field).val("Autocompleted " + field); | |
$("#shipping_address_" + field).hide(); | |
} | |
$(document).ready(function() { | |
// Name | |
autoHide("name"); | |
// Surname | |
autoHide("surname"); | |
// Full Street Address | |
autoHide("address"); | |
// City | |
autoHide("city"); | |
}); | |
/* Special Cases: Country and Regions need to wait for the list to load before autocompleting */ | |
// Selects and hides the Country | |
country_selected = false | |
function selectHideCountry() { | |
$("#shipping_address_country").hide() | |
var interval_c = setInterval(function() { | |
if ($("#order_shipping_address_country").val() == "") { | |
$("#order_shipping_address_country option:last").attr("selected", "selected"); | |
var sortBySelect = document.querySelector("#order_shipping_address_country"); | |
sortBySelect.dispatchEvent(new Event("change")); | |
} else { | |
clearInterval(interval_c) | |
country_selected = true | |
} | |
}, 500); | |
} | |
// Selects and hides the Region | |
region_selected = false | |
function selectHideRegion() { | |
$("#shipping_address_region").hide() | |
var interval_r = setInterval(function() { | |
if ($("#order_shipping_address_region").val() == "" && country_selected) { | |
$("#order_shipping_address_region option:last").attr("selected", "selected"); | |
} else { | |
clearInterval(interval_r) | |
region_selected = true | |
} | |
}, 500); | |
} | |
$(document).ready(function() { | |
selectHideCountry() | |
selectHideRegion() | |
}); | |
// Optional hides all (Don't use this if you didn't use the previous functions) | |
$(document).ready(function() { | |
$("#shipping_address").hide(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment