From 3762895a729635fa4944e52d3588caa2196182a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Wed, 4 Oct 2023 22:29:25 +0200 Subject: [PATCH] Wrap inline `remove_from_cart` script in IIFE To avoid syntax errors for const re-declaration. Quick fix for https://wordpress.org/support/topic/javascript-output-twice/#post-17098290 --- includes/class-wc-google-gtag-js.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-google-gtag-js.php b/includes/class-wc-google-gtag-js.php index fc4606de..6dd1ab7b 100644 --- a/includes/class-wc-google-gtag-js.php +++ b/includes/class-wc-google-gtag-js.php @@ -394,10 +394,12 @@ public function remove_from_cart() { // we listen for clicks on `.woocommerce` container(s), // as `.woocommerce-cart-form` and its items are re-rendered on each removal. wc_enqueue_js( - "const selector = '.woocommerce-cart-form__cart-item .remove'; - $( '.woocommerce' ).off('click', selector).on( 'click', selector, function() { - $event_code - });" + "(function(){ + const selector = '.woocommerce-cart-form__cart-item .remove'; + $( '.woocommerce' ).off('click', selector).on( 'click', selector, function() { + $event_code + }); + })();" ); }