Skip to content

Instantly share code, notes, and snippets.

@aatronco
Created May 3, 2021 20:03
Show Gist options
  • Save aatronco/749fbf29efff7fde38e70117e77193d4 to your computer and use it in GitHub Desktop.
Save aatronco/749fbf29efff7fde38e70117e77193d4 to your computer and use it in GitHub Desktop.
<script>
const shipping_method_id = 1234556 // id of free shipping option
const normal_shipping = 654321 // id of normal shipping option
const municipalities_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
const products_free_shipping = ["merchant needs to complete this field"] // Ideally a theme option separated by comma
var conditions = function() {
// certain product is in the cart and certain municipalities are selected. The work is to construct this function
}
var special_shipping = function() {
if (conditions()) {
$('#shipping_options input[value=' + shipping_method_id + ']').parent().show();
} else {
$('#shipping_options input[value=' + shipping_method_id + ']').parent().hide();
$('#shipping_options input[value=' + normal_shipping + ']').click();
}
}
// Execute the function
$(document).ready(special_shipping);
$(checkout).change(special_shipping);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment