Created
June 6, 2024 14:21
-
-
Save joseacat/eddf63dc7ff862be7e94ed4ba7cbee40 to your computer and use it in GitHub Desktop.
Evento en JS tras añadir al carrito en Woocommerce
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
// Abrir carrito tras añadir al carrito | |
var btns_anadir_producto = document.querySelectorAll('.single_add_to_cart_button') | |
btns_anadir_producto.forEach(function (btn_anadir_producto) { | |
var prevClassState = btn_anadir_producto.classList.contains('added'); | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if(mutation.attributeName == "class"){ | |
var currentClassState = mutation.target.classList.contains('added'); | |
if(prevClassState !== currentClassState) { | |
prevClassState = currentClassState; | |
if(currentClassState){ | |
// Aquí el código .... | |
} | |
} | |
} | |
}); | |
}); | |
observer.observe(btn_anadir_producto, {attributes: true}); | |
})*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment