Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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