Skip to content

Commit

Permalink
Listen for cart remove on the enclosing container,
Browse files Browse the repository at this point in the history
as cart form and items are being re-rendered.

Fixes #282
  • Loading branch information
tomalec committed Jul 5, 2023
1 parent 319a359 commit a9281cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion includes/class-wc-google-gtag-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,12 @@ public function remove_from_cart() {
}]}'
);

// To track all the consecutive removals,
// we listen for clicks on `.woocommerce` container(s),
// as `.woocommerce-cart-form` and its items are re-rendered on each removal.
wc_enqueue_js(
"$( '.remove' ).off('click', '.remove').on( 'click', function() {
"const selector = '.woocommerce-cart-form__cart-item .remove';
$( '.woocommerce' ).off('click', selector).on( 'click', selector, function() {
$event_code
});"
);
Expand Down

0 comments on commit a9281cc

Please sign in to comment.