Skip to content

Instantly share code, notes, and snippets.

@joseacat
Created June 6, 2024 14:21
Show Gist options
  • Save joseacat/eddf63dc7ff862be7e94ed4ba7cbee40 to your computer and use it in GitHub Desktop.
Save joseacat/eddf63dc7ff862be7e94ed4ba7cbee40 to your computer and use it in GitHub Desktop.
Evento en JS tras añadir al carrito en Woocommerce
// 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