Skip to content

Instantly share code, notes, and snippets.

@be-mohand
Created February 22, 2022 15:44
Show Gist options
  • Save be-mohand/ac3f41f3c5ad24c7f97e65022b136a7a to your computer and use it in GitHub Desktop.
Save be-mohand/ac3f41f3c5ad24c7f97e65022b136a7a to your computer and use it in GitHub Desktop.
Use this JavaScript snippet to make sure at least one shipping method is selected if shipping is enabled when we use the AddOns as shipping selector
/**
* Making sure at least one shipping method is selected if shipping is enabled
*/
if(typeof Kr !== 'undefined' && typeof Kr.Listing !== 'undefined' && Kr.Listing !== null && document.querySelectorAll('input[name="addons"]').length > 0)
{
let checkIfShippingHasBeenSelected = function() {
if(document.querySelectorAll('input[name="addons"]:checked').length === 0) {
[].forEach.call(document.querySelectorAll('input[name="addons"]:first-child'), function (el) {el.checked = true});
}
}
checkIfShippingHasBeenSelected();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment