I try to write a function to show/hide Add to cart button (WooCommerce) when the price of product is zero - 0,00 €. When the page loads and the product has this zero price it should hide the product Add to cart button and when I chose an option and the price change, for example to 30,00 €, then it should show the button. In console.log() I see the prices change but the condition to show/hide the button doesn't work.
var zeroVal = "0,00 €",
newVal = jQuery('.price').text();
jQuery('.price').change(function(){
if(newVal == zeroVal) {
jQuery('.single_add_to_cart_button').attr("style","display: none!important");
} else {
jQuery('.single_add_to_cart_button').attr("style","display: block!important");
}
});
function priceChangeListener() {
if(newVal != zeroVal) {
newVal = jQuery('.price').text();
}
jQuery('.price').change();
};
setInterval(priceChangeListener, 500);
What do I do wrong? Is there any simpler solution? I was not able to find any. Thanks for any help provided.