Skip to content

Instantly share code, notes, and snippets.

@gje4
Last active October 13, 2023 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gje4/9470a9030d9266fb150265a027c07b5b to your computer and use it in GitHub Desktop.
Save gje4/9470a9030d9266fb150265a027c07b5b to your computer and use it in GitHub Desktop.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script>
var obs = new MutationObserver(function(mutations, observer) {
$.each(mutations, function(i, mutation) {
var addedNodes = $(mutation.addedNodes);
var selector = "form, .checkout-step-info";
var filteredEls = addedNodes.find(selector).addBack(selector);
filteredEls.each(function() {
//get customer and adjust payment methods
let customerData = JSON.parse({{customer}});
console.log(customerData);
//add logic based on a customer attribute of your chossing
payment(customerData)
});
});
});
const config = { childList: true, subtree: true };
function addObserverIfDesiredNodeAvailable() {
var composeBox = document.querySelectorAll(".checkout-step--shipping")[0];
if(!composeBox) {
//The node we need does not exist yet. //Wait 500ms and try again
window.setTimeout(addObserverIfDesiredNodeAvailable,500);
return;
}
obs.observe($(".checkout-step--shipping")[0], config);
}
function payment(){
if(customerGroup !== '2') {
document.getElementById('radio-moneyorder').type = 'hidden';
}
else {
document.getElementById('radio-moneyorder').type = 'visible';
}
}
addObserverIfDesiredNodeAvailable();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment