John Davidson

php - JS to track WooCommerce Events

0 comments
Message:


We can use the hooks to catch the events in the woocommerce like :


add_action('woocommerce_single_product_summary', array(
&$this,
'viewed_product'
) , 15);

Is there any similar thing that can be done in JS?
I need to find similar JS events for Cart Viewed, Product Searched ...etc


I am using these to track add to cart and remove from cart,


singpleProductAddToCartEventBind() {
let single_btn = document.querySelectorAll(
"button[class*='btn-buy-shop'],button[class*='single_add_to_cart_button'], button[class*='add_to_cart']"
);

if (single_btn.length > 0) {
single_btn[0].addEventListener("click", () => this.addToCartClick());
}
}




removeFromCartEventBind() {
document.body.addEventListener("click", (e) => {
const classList = e.target.className.split(" ");
const removeClasses = ["remove", "remove_from_cart_button"];
if (removeClasses.some((el) => classList.includes(el))) {
this.removeFromCart();
}
});
}


My Answer:
($this, 'track_product_view'));

function track_product_view() {
?>

}

Rate this post

4 of 5 based on 3252 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us