Support Center

Javascript Snippet: Remove Shipping Methods from Checkout

Use Javascript Responsibly: Other apps and theme elements may contain Javascript code that might interfere with yours. If you are not sure about the effects of this code contact a professional.

This code will allow you to disable Shipping Methods depending on the selected Region. A similar code can be use on the cart page.


<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>

gistMarkdown.js

Start your journey with us!

Free trial for 14 days. No credit card required.