Last active
November 4, 2020 15:56
-
-
Save aatronco/c9efa0276b64ee41eaf23044a23ff191 to your computer and use it in GitHub Desktop.
This file contains 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
<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