Home > Back-end >  JS to track WooCommerce Events
JS to track WooCommerce Events

Time:09-15

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();
      }
    });
  }

CodePudding user response:

Was found the bunch of codes in assets/js/frontend

  • Related