From 8ef5d1901eb83a8fd132b8eadf7bfc136020157d Mon Sep 17 00:00:00 2001 From: Miguel Perez Pellicer <5908855+puntope@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:34:27 +0400 Subject: [PATCH] Fix listing and add_to_cart for blocks --- includes/class-wc-google-analytics.php | 4 ++-- includes/class-wc-google-gtag-js.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-google-analytics.php b/includes/class-wc-google-analytics.php index 6a5f3525..b6ed1722 100644 --- a/includes/class-wc-google-analytics.php +++ b/includes/class-wc-google-analytics.php @@ -131,8 +131,8 @@ public function __construct() { add_action( 'woocommerce_after_cart', array( $this, 'remove_from_cart' ) ); add_action( 'woocommerce_after_mini_cart', array( $this, 'remove_from_cart' ) ); add_filter( 'woocommerce_cart_item_remove_link', array( $this, 'remove_from_cart_attributes' ), 10, 2 ); - add_action( 'woocommerce_after_shop_loop_item', array( $this, 'listing_impression' ) ); - add_action( 'woocommerce_after_shop_loop_item', array( $this, 'listing_click' ) ); + add_action( 'woocommerce_after_shop_loop_item_title', array( $this, 'listing_click' ) ); + add_action( 'woocommerce_after_shop_loop_item_title', array( $this, 'listing_impression' ) ); add_action( 'woocommerce_after_single_product', array( $this, 'product_detail' ) ); add_action( 'woocommerce_after_checkout_form', array( $this, 'checkout_process' ) ); diff --git a/includes/class-wc-google-gtag-js.php b/includes/class-wc-google-gtag-js.php index cfceb20e..b74a2d88 100644 --- a/includes/class-wc-google-gtag-js.php +++ b/includes/class-wc-google-gtag-js.php @@ -226,7 +226,7 @@ public static function listing_click( $product, $position ) { wc_enqueue_js( " - $( '.products .post-" . esc_js( $product->get_id() ) . " a' ).on('click', function() { + $( '.product.post-" . esc_js( $product->get_id() ) . " a , .product.post-" . esc_js( $product->get_id() ) . " button' ).on('click', function() { if ( true === $(this).hasClass( 'add_to_cart_button' ) ) { $add_to_cart_event_code } else {