Last active
October 13, 2023 22:59
-
-
Save gje4/9470a9030d9266fb150265a027c07b5b 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 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