Skip to content

Instantly share code, notes, and snippets.

@aatronco
Last active November 4, 2020 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aatronco/c9efa0276b64ee41eaf23044a23ff191 to your computer and use it in GitHub Desktop.
Save aatronco/c9efa0276b64ee41eaf23044a23ff191 to your computer and use it in GitHub Desktop.
<script>
// Define the shipping method for the local region (metropolitana) and for all others.
let metropolitana = 267131
let others = "22276-service"
// Function verifies if customer selected the local region (Metropolitana).
function metropolitanaIsSelected() {
return $.inArray($.trim($("#order_shipping_address_region option:selected").text()), ["Metropolitana"]) > -1;
};
// Function to hide/show the correct local method.
var shippingController = function() {
if (metropolitanaIsSelected()) {
$("input[value=" + metropolitana + "]").parent().show()
} else {
$("input[value=" + others + "]").parent().show()
$("input[value=" + others + "]").click()
$("input[value=" + metropolitana + "]").parent().hide()
}
};
// Applies the funcion on document and region select load and after changing the region.
$(document).ready(function() {
Jumpseller.regionListener("#order_shipping_address_region", {
callback: shippingController
});
})
$("#order_shipping_address_region").change(shippingController);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment