diff --git a/assets/integration/woocommerce.js b/assets/integration/woocommerce.js index cfea05f..83acd7e 100644 --- a/assets/integration/woocommerce.js +++ b/assets/integration/woocommerce.js @@ -1 +1 @@ -function gtmkitLoad(){const a=window.gtmkit_settings.datalayer_name;let n;const d={"wp-block-handpicked-products":1,"wp-block-product-best-sellers":1,"wp-block-product-category":1,"wp-block-product-new":1,"wp-block-product-on-sale":1,"wp-block-products-by-attribute":1,"wp-block-product-tag":1,"wp-block-product-top-rated":1};document.querySelectorAll(".wc-block-grid .wc-block-grid__product").forEach(function(t){var e=t.closest(".wc-block-grid"),i=t.querySelector(".gtmkit_product_data");if(e&&i){var r,c=e.classList;if(c)for(const o in d)c.contains(o)&&((r=JSON.parse(i.getAttribute("data-gtmkit_product_data"))).item_list_name=window.gtmkit_settings.wc.text[o],r.index=d[o],i.setAttribute("data-gtmkit_product_data",JSON.stringify(r)),d[o]++)}});var t=document.querySelectorAll(".gtmkit_product_data");if(t.length){const i=[];let e;t.forEach(function(t){e=JSON.parse(t.getAttribute("data-gtmkit_product_data")),i.push(e)}),window[a].push({ecommerce:null}),window[a].push({event:"view_item_list",ecommerce:{items:i}})}document.addEventListener("click",function(t){t=t.target;let e;if(!t)return!0;if(t.closest(".add_to_cart_button.ajax_add_to_cart:not(.single_add_to_cart_button)"))e="add_to_cart";else{if(!t.closest(".products")&&!t.closest(".wc-block-grid__products")||!t.closest(window.gtmkit_settings.wc.css_selectors.product_list_wishlist))return!0;e="add_to_wishlist"}t=t.closest(".product,.wc-block-grid__product"),t=t&&t.querySelector(".gtmkit_product_data");if(!t)return!0;t=JSON.parse(t.getAttribute("data-gtmkit_product_data"));t.quantity=1,window[a].push({ecommerce:null}),window[a].push({event:e,ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price,items:[t]}})}),document.addEventListener("click",function(r){r=r.target;if(!r)return!0;let c,i=r.closest("form.cart");if(!i){let t=r.parentNode;for(;!i&&t;)i=t.querySelector("form.cart"),t=t.parentNode}if(!i)return!0;if(r.closest(".single_add_to_cart_button:not(.disabled,.input-needed)"))c="add_to_cart";else{if(!r.closest(window.gtmkit_settings.wc.css_selectors.single_product_wishlist))return!0;c="add_to_wishlist"}var r=i.querySelectorAll("[name=variation_id]"),t=i.classList&&i.classList.contains("grouped_form")&&!i.classList.contains("bundle_form");if(r.length){let t=1,e;n&&(r=i.querySelector("[name=quantity]"),n.quantity=r&&r.value||1,t=n.quantity,e=n.price),(n&&"add_to_cart"===c||"add_to_wishlist"===c)&&(window[a].push({ecommerce:null}),window[a].push({event:c,ecommerce:{currency:window.gtmkit_data.wc.currency,value:e*t,items:[n]}}))}else if(t){r=document.querySelectorAll(".grouped_form .gtmkit_product_data");const o=[];let i=0;if(r.forEach(function(t){let e=document.querySelectorAll("input[name=quantity\\["+t.getAttribute("data-gtmkit_product_id")+"\\]]");if(e=Number(e[0].value),0===(e=isNaN(e)?0:e)&&"add_to_cart"===c)return!0;0===e&&"add_to_wishlist"===c&&(e=1);t=JSON.parse(t.getAttribute("data-gtmkit_product_data"));t.quantity=e,o.push(t),i+=t.price*t.quantity}),0===o.length)return!0;window[a].push({ecommerce:null}),window[a].push({event:c,ecommerce:{currency:window.gtmkit_data.wc.currency,value:i,items:o}})}else{t=JSON.parse(i.querySelector("[name=gtmkit_product_data]")&&i.querySelector("[name=gtmkit_product_data]").value);t.quantity=i.querySelector("[name=quantity]")&&i.querySelector("[name=quantity]").value,window[a].push({ecommerce:null}),window[a].push({event:c,ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price*t.quantity,items:[t]}})}}),document.addEventListener("click",function(t){var t=t.target;return!t||!t.closest(".mini_cart_item a.remove,.product-remove a.remove")||!(t=JSON.parse(t.getAttribute("data-gtmkit_product_data")))||(window[a].push({ecommerce:null}),void window[a].push({event:"remove_from_cart",ecommerce:{items:[t]}}))}),document.addEventListener("click",function(t){t=t.target;if(!t.closest(window.gtmkit_settings.wc.css_selectors.product_list_select_item))return!0;var t=t.closest(".product,.wc-block-grid__product");let e;return!t||!(e=t.querySelector(".gtmkit_product_data"))||void 0===e.getAttribute("data-gtmkit_product_data")||!(t=JSON.parse(e.getAttribute("data-gtmkit_product_data")))||(window[a].push({ecommerce:null}),void window[a].push({event:"select_item",ecommerce:{items:[t]}}))}),jQuery(document).on("found_variation",function(t,e){if(void 0!==e){t=t.target;if(t.querySelector("[name=gtmkit_product_data]")){var t=JSON.parse(t.querySelector("[name=gtmkit_product_data]")&&t.querySelector("[name=gtmkit_product_data]").value),i=(t.id=t.item_id=window.gtmkit_settings.wc.pid_prefix+e.variation_id,window.gtmkit_settings.wc.use_sku&&e.sku&&""!==e.sku&&(t.id=t.item_id=window.gtmkit_settings.wc.pid_prefix+e.sku),t.price=e.display_price,[]);for(const r in e.attributes)i.push(e.attributes[r]);t.item_variant=i.filter(t=>t).join("|"),n=t,0!==window.gtmkit_settings.wc.view_item.config&&(window[a].push({ecommerce:null}),window[a].push({event:"view_item",ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price,items:[t]}})),!0===window.gtmkit_settings.console_log&&(console.log("GTM Kit: selectedProductVariationData"),console.log(n))}}})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",gtmkitLoad):gtmkitLoad(); \ No newline at end of file +function gtmkitLoad(){const n=window.gtmkit_settings.datalayer_name;let a;const d={"wp-block-handpicked-products":1,"wp-block-product-best-sellers":1,"wp-block-product-category":1,"wp-block-product-new":1,"wp-block-product-on-sale":1,"wp-block-products-by-attribute":1,"wp-block-product-tag":1,"wp-block-product-top-rated":1};document.querySelectorAll(".wc-block-grid .wc-block-grid__product").forEach(function(t){var e=t.closest(".wc-block-grid"),i=t.querySelector(".gtmkit_product_data");if(e&&i){var c,r=e.classList;if(r)for(const o in d)r.contains(o)&&((c=JSON.parse(i.getAttribute("data-gtmkit_product_data"))).item_list_name=window.gtmkit_settings.wc.text[o],c.index=d[o],i.setAttribute("data-gtmkit_product_data",JSON.stringify(c)),d[o]++)}});var t=document.querySelectorAll(".gtmkit_product_data");if(t.length){const i=[];let e;t.forEach(function(t){e=JSON.parse(t.getAttribute("data-gtmkit_product_data")),i.push(e)}),window[n].push({ecommerce:null}),window[n].push({event:"view_item_list",ecommerce:{items:i}})}document.addEventListener("click",function(t){t=t.target;let e;if(!t)return!0;if(t.closest(".add_to_cart_button.ajax_add_to_cart:not(.single_add_to_cart_button)"))e="add_to_cart";else{if(!window.gtmkit_settings.wc.wishlist||!t.closest(".products")&&!t.closest(".wc-block-grid__products")||!t.closest(window.gtmkit_settings.wc.css_selectors.product_list_wishlist))return!0;e="add_to_wishlist"}t=t.closest(".product,.wc-block-grid__product"),t=t&&t.querySelector(".gtmkit_product_data");if(!t)return!0;t=JSON.parse(t.getAttribute("data-gtmkit_product_data"));t.quantity=1,window[n].push({ecommerce:null}),window[n].push({event:e,ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price,items:[t]}})}),document.addEventListener("click",function(c){c=c.target;if(!c)return!0;let r,i=c.closest("form.cart");if(!i){let t=c.parentNode;for(;!i&&t;)i=t.querySelector("form.cart"),t=t.parentNode}if(!i)return!0;if(c.closest(".single_add_to_cart_button:not(.disabled,.input-needed)"))r="add_to_cart";else{if(!window.gtmkit_settings.wc.wishlist||!c.closest(window.gtmkit_settings.wc.css_selectors.single_product_wishlist))return!0;r="add_to_wishlist"}var c=i.querySelectorAll("[name=variation_id]"),t=i.classList&&i.classList.contains("grouped_form")&&!i.classList.contains("bundle_form");if(c.length){let t=1,e;a&&(c=i.querySelector("[name=quantity]"),a.quantity=c&&c.value||1,t=a.quantity,e=a.price),(a&&"add_to_cart"===r||"add_to_wishlist"===r)&&(window[n].push({ecommerce:null}),window[n].push({event:r,ecommerce:{currency:window.gtmkit_data.wc.currency,value:e*t,items:[a]}}))}else if(t){c=document.querySelectorAll(".grouped_form .gtmkit_product_data");const o=[];let i=0;if(c.forEach(function(t){let e=document.querySelectorAll("input[name=quantity\\["+t.getAttribute("data-gtmkit_product_id")+"\\]]");if(e=Number(e[0].value),0===(e=isNaN(e)?0:e)&&"add_to_cart"===r)return!0;0===e&&"add_to_wishlist"===r&&(e=1);t=JSON.parse(t.getAttribute("data-gtmkit_product_data"));t.quantity=e,o.push(t),i+=t.price*t.quantity}),0===o.length)return!0;window[n].push({ecommerce:null}),window[n].push({event:r,ecommerce:{currency:window.gtmkit_data.wc.currency,value:i,items:o}})}else{t=JSON.parse(i.querySelector("[name=gtmkit_product_data]")&&i.querySelector("[name=gtmkit_product_data]").value);t.quantity=i.querySelector("[name=quantity]")&&i.querySelector("[name=quantity]").value,window[n].push({ecommerce:null}),window[n].push({event:r,ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price*t.quantity,items:[t]}})}}),document.addEventListener("click",function(t){var t=t.target;return!t||!t.closest(".mini_cart_item a.remove,.product-remove a.remove")||!(t=JSON.parse(t.getAttribute("data-gtmkit_product_data")))||(window[n].push({ecommerce:null}),void window[n].push({event:"remove_from_cart",ecommerce:{items:[t]}}))}),document.addEventListener("click",function(t){t=t.target;if(!t.closest(window.gtmkit_settings.wc.css_selectors.product_list_select_item))return!0;var t=t.closest(".product,.wc-block-grid__product");let e;return!t||!(e=t.querySelector(".gtmkit_product_data"))||void 0===e.getAttribute("data-gtmkit_product_data")||!(t=JSON.parse(e.getAttribute("data-gtmkit_product_data")))||(window[n].push({ecommerce:null}),void window[n].push({event:"select_item",ecommerce:{items:[t]}}))}),jQuery(document).on("found_variation",function(t,e){if(void 0!==e){t=t.target;if(t.querySelector("[name=gtmkit_product_data]")){var t=JSON.parse(t.querySelector("[name=gtmkit_product_data]")&&t.querySelector("[name=gtmkit_product_data]").value),i=(t.id=t.item_id=window.gtmkit_settings.wc.pid_prefix+e.variation_id,window.gtmkit_settings.wc.use_sku&&e.sku&&""!==e.sku&&(t.id=t.item_id=window.gtmkit_settings.wc.pid_prefix+e.sku),t.price=e.display_price,[]);for(const c in e.attributes)i.push(e.attributes[c]);t.item_variant=i.filter(t=>t).join("|"),a=t,0!==window.gtmkit_settings.wc.view_item.config&&(window[n].push({ecommerce:null}),window[n].push({event:"view_item",ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.price,items:[t]}})),!0===window.gtmkit_settings.console_log&&(console.log("GTM Kit: selectedProductVariationData"),console.log(a))}}})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",gtmkitLoad):gtmkitLoad(); \ No newline at end of file diff --git a/src/Admin/PluginAvailability.php b/src/Admin/PluginAvailability.php index ae1a4df..67caef3 100644 --- a/src/Admin/PluginAvailability.php +++ b/src/Admin/PluginAvailability.php @@ -27,6 +27,7 @@ final class PluginAvailability { public function register() { $this->seo_plugins(); $this->conflicting_plugins(); + $this->wishlist_plugins(); $this->register_plugins(); } @@ -76,6 +77,27 @@ protected function conflicting_plugins() { ]; } + /** + * Wishlist plugins. + * + * @return void + */ + protected function wishlist_plugins() { + $this->plugins['wishlist_plugins'] = [ + 'yith-woocommerce-wishlist' => [ + 'name' => 'YITH WooCommerce Wishlist', + 'slug' => 'yith-woocommerce-wishlist/init.php', + 'gf' => true, + ], + + 'gtm-ecommerce-woo-pro' => [ + 'name' => 'TI WooCommerce Wishlist', + 'slug' => 'ti-woocommerce-wishlist/ti-woocommerce-wishlist.php', + 'gf' => true, + ], + ]; + } + /** * Registers the plugins status. * @@ -133,4 +155,15 @@ public function get_plugins( string $category = '' ): array { public function is_active( array $plugin ): bool { return isset( $plugin['active'] ) && $plugin['active'] === true; } + + /** + * Determines whether a grandfathered polyfill is available. + * + * @param array $plugin The plugin to check. + * + * @return bool Whether the plugin is active. + */ + public function gf_polyfill_available( array $plugin ): bool { + return isset( $plugin['gf'] ) && $plugin['gf'] === true; + } } diff --git a/src/Admin/PluginSuggestions.php b/src/Admin/PluginSuggestions.php index 6c4bd43..1e4f743 100644 --- a/src/Admin/PluginSuggestions.php +++ b/src/Admin/PluginSuggestions.php @@ -8,7 +8,9 @@ namespace TLA_Media\GTM_Kit\Admin; use TLA_Media\GTM_Kit\Common\Conditionals\EasyDigitalDownloadsConditional; +use TLA_Media\GTM_Kit\Common\Conditionals\PremiumConditional; use TLA_Media\GTM_Kit\Common\Conditionals\WooCommerceConditional; +use TLA_Media\GTM_Kit\Options; /** * Suggested plugins @@ -20,14 +22,14 @@ final class PluginSuggestions { * * @var PluginAvailability */ - protected $plugin_availability; + protected PluginAvailability $plugin_availability; /** * An instance of NotificationsHandler. * * @var NotificationsHandler */ - private $notifications_handler; + private NotificationsHandler $notifications_handler; /** * Constructor. @@ -52,8 +54,57 @@ public static function register( NotificationsHandler $notifications_handler, Pl $page = new self( $notifications_handler, $plugin_availability ); add_action( 'admin_init', [ $page->plugin_availability, 'register' ] ); + add_action( 'admin_init', [ $page, 'suggest_premium' ] ); add_action( 'admin_init', [ $page, 'suggest_seo_plugin' ] ); add_action( 'admin_init', [ $page, 'detect_conflicting_plugins' ] ); + add_action( 'admin_init', [ $page, 'suggest_grandfathered_wishlist' ] ); + } + + /** + * Suggest GTM Kit Woo Add-On. + * + * @return void + */ + public function suggest_premium(): void { + + $notification_id = 'gtmkit-premium-woo'; + + if ( ! ( + ( new WooCommerceConditional() )->is_met() && + ! ( new PremiumConditional() )->is_met() && + ! Options::init()->get( 'misc', 'gf_wishlist' ) === true ) + ) { + $this->notifications_handler->remove_notification_by_id( $notification_id ); + return; + } + + $add_notification = false; + + $plugins = $this->plugin_availability->get_plugins( 'wishlist_plugins' ); + $extensions = [ + 'plugin' => '', + 'theme' => '', + ]; + + foreach ( $plugins as $plugin ) { + if ( $this->plugin_availability->is_active( $plugin ) ) { + $extensions['plugin'] = $plugin['name']; + $add_notification = true; + + break; + } + } + + if ( \wp_get_theme()->get( 'Name' ) === 'Woodmart' || wp_get_theme()->get( 'Template' ) === 'woodmart' ) { + $extensions['theme'] = 'woodmart'; + } + + if ( $add_notification ) { + $notification = $this->get_premium_notification( $notification_id, $extensions ); + $this->notifications_handler->add_notification( $notification ); + } else { + $this->notifications_handler->remove_notification_by_id( $notification_id ); + } } /** @@ -109,6 +160,94 @@ public function detect_conflicting_plugins(): void { } } + /** + * Suggest a supported SEO plugin. + * + * @return void + */ + public function suggest_grandfathered_wishlist(): void { + $notification_id = 'gtmkit-gf_wishlist'; + + if ( ! ( + ( new WooCommerceConditional() )->is_met() && + ! ( new PremiumConditional() )->is_met() && + Options::init()->get( 'misc', 'gf_wishlist' ) === true ) + ) { + $this->notifications_handler->remove_notification_by_id( $notification_id ); + return; + } + + $add_notification = false; + + if ( ! defined( 'GTMKIT_GF_WISHLIST_VERSION' ) ) { + $plugins = $this->plugin_availability->get_plugins( 'wishlist_plugins' ); + + foreach ( $plugins as $plugin ) { + if ( $this->plugin_availability->is_active( $plugin ) && $this->plugin_availability->gf_polyfill_available( $plugin ) ) { + $add_notification = true; + + break; + } + } + } + + if ( $add_notification ) { + $notification = $this->get_gf_wishlist_plugin_notification( $notification_id ); + $this->notifications_handler->add_notification( $notification ); + } else { + $this->notifications_handler->remove_notification_by_id( $notification_id ); + } + } + + /** + * Build premium plugin notification. + * + * @param string $notification_id The id of the notification to be created. + * @param array $extensions The plugin data. + * + * @return Notification The notification containing the suggested plugin. + */ + protected function get_premium_notification( string $notification_id, array $extensions ): Notification { + + $message = ''; + + if ( ! empty( $extensions['plugin'] ) && ! empty( $extensions['theme'] ) ) { + $message = sprintf( + /* translators: %1$s is the name of the plugin and %2$s is the name of the theme. */ + __( 'It seems that you have installed the %1$s plugin and %1$s theme.', 'gtm-kit' ), + $extensions['plugin'], + $extensions['theme'] + ) . ' '; + } elseif ( ! empty( $extensions['plugin'] ) ) { + $message = sprintf( + /* translators: %1$s is the name of the plugin. */ + __( 'It seems that you have installed the %1$s plugin.', 'gtm-kit' ), + $extensions['plugin'], + $extensions['theme'] + ) . ' '; + } elseif ( ! empty( $extensions['theme'] ) ) { + $message = sprintf( + /* translators: %1$s is the name of the theme. */ + __( 'It seems that you have installed the %1$s theme.', 'gtm-kit' ), + $extensions['plugin'], + $extensions['theme'] + ) . ' '; + } + + $link = 'GTM Kit Woo Add-On'; + $message .= sprintf( + /* translators: %1$s is a link with the text 'GTM Kit Woo Add-On'. */ + __( 'With the %1$s, you can track the add_to_wishlist event and leverage server-side tracking for enhanced accuracy and deeper insights into customer behavior.', 'gtm-kit' ), + $link, + ); + + return $this->new_notification( + $notification_id, + $message, + __( 'Upgrade:', 'gtm-kit' ) + ); + } + /** * Build suggestion of SEO plugin notification. * @@ -154,6 +293,35 @@ protected function get_conflicting_plugin_notification( string $notification_id, ); } + + /** + * Build GF wishlist notification. + * + * @param string $notification_id The id of the notification to be created. + * + * @return Notification The notification containing the suggested plugin. + */ + protected function get_gf_wishlist_plugin_notification( string $notification_id ): Notification { + + $link_1 = 'GTM Kit Woo Add-On'; + $link_2 = 'Grandfathered Wishlist Functionality'; + + $message = sprintf( + /* translators: %1$s and %2$s are links with the text 'GTM Kit Woo Add-On' and 'Grandfathered Wishlist Functionality' respectively. */ + __( 'Starting with GTM Kit version 2.0, the add_to_wishlist event is no longer supported in the free version of GTM Kit. To continue tracking the add_to_wishlist event, you must either purchase the %1$s or download the free %2$s plugin.', 'gtm-kit' ), + $link_1, + $link_2 + ); + + return $this->new_notification( + $notification_id, + $message, + __( 'Breaking change:', 'gtm-kit' ), + Notification::PROBLEM + ); + } + + /** * New notification. * diff --git a/src/Installation/Upgrade.php b/src/Installation/Upgrade.php index 0a70ba7..c45319c 100644 --- a/src/Installation/Upgrade.php +++ b/src/Installation/Upgrade.php @@ -7,6 +7,7 @@ namespace TLA_Media\GTM_Kit\Installation; +use TLA_Media\GTM_Kit\Common\Conditionals\WooCommerceConditional; use TLA_Media\GTM_Kit\Options; /** @@ -44,6 +45,7 @@ protected function get_upgrades(): array { '1.15' => 'v115_upgrade', '1.20' => 'v120_upgrade', '1.22' => 'v122_upgrade', + '2.0' => 'v2_upgrade', ]; $current_version = \get_option( 'gtmkit_version' ); @@ -153,4 +155,23 @@ protected function v122_upgrade(): void { Options::init()->set( $values, false, false ); } + + /** + * Upgrade routine for v2.0 + */ + protected function v2_upgrade(): void { + + if ( ( + new WooCommerceConditional() )->is_met() && + ( is_plugin_active( 'yith-woocommerce-wishlist/init.php' ) || is_plugin_active( 'ti-woocommerce-wishlist/ti-woocommerce-wishlist.php' ) + ) ) { + $values = [ + 'misc' => [ + 'gf_wishlist' => true, + ], + ]; + + Options::init()->set( $values, false, false ); + } + } } diff --git a/src/Integration/WooCommerce.php b/src/Integration/WooCommerce.php index 4312288..d0a4645 100644 --- a/src/Integration/WooCommerce.php +++ b/src/Integration/WooCommerce.php @@ -112,8 +112,6 @@ public static function register( Options $options, Util $util ): void { 20, 3 ); - add_filter( 'tinvwl_wishlist_item_meta_post', [ self::$instance, 'Compatibility_With_TI_Wishlist' ] ); - add_action( 'woocommerce_after_shop_loop_item', [ self::$instance, 'product_list_loop_add_to_cart_tracking' ] ); add_filter( 'woocommerce_cart_item_remove_link', [ self::$instance, 'cart_item_remove_link' ], 10, 2 ); @@ -245,6 +243,7 @@ public function get_global_settings( array $global_settings ): array { $global_settings['wc']['add_payment_info']['config'] = (int) $this->options->get( 'integrations', 'woocommerce_payment_info' ); $global_settings['wc']['view_item']['config'] = (int) $this->options->get( 'integrations', 'woocommerce_variable_product_tracking' ); $global_settings['wc']['view_item_list']['config'] = (int) $this->options->get( 'integrations', 'woocommerce_view_item_list_limit' ); + $global_settings['wc']['wishlist'] = false; $global_settings['wc']['text'] = [ 'wp-block-handpicked-products' => __( 'Handpicked Products', 'gtm-kit' ), 'wp-block-product-best-sellers' => __( 'Best Sellers', 'gtm-kit' ), @@ -258,11 +257,9 @@ public function get_global_settings( array $global_settings ): array { 'payment-method-not-found' => __( 'Payment method not found', 'gtm-kit' ), ]; $global_settings['wc']['css_selectors'] = [ - 'single_product_wishlist' => '.add_to_wishlist, .tinvwl_add_to_wishlist_button:not(.tinvwl-product-in-list,.disabled-add-wishlist)', - 'product_list_select_item' => '.products .product:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist,.tinvwl_add_to_wishlist_button),' . - '.wc-block-grid__products li:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist,.tinvwl_add_to_wishlist_button),' . - '.woocommerce-grouped-product-list-item__label a:not(.add_to_wishlist,.tinvwl_add_to_wishlist_button)', - 'product_list_wishlist' => '.add_to_wishlist, .tinvwl_add_to_wishlist_button:not(.tinvwl-product-in-list)', + 'product_list_select_item' => '.products .product:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist),' . + '.wc-block-grid__products li:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist),' . + '.woocommerce-grouped-product-list-item__label a:not(.add_to_wishlist)', ]; return $global_settings; @@ -1045,24 +1042,6 @@ public function prefix_item_id( string $item_id = '' ): string { return $this->options->get( 'integrations', 'woocommerce_product_id_prefix' ) . $item_id; } - /** - * Compatibility with TI WooCommerce Wishlist - * - * @param array $item_data Item data. - * - * @return array - */ - public function Compatibility_With_TI_Wishlist( array $item_data ): array { - - foreach ( array_keys( $item_data ) as $key ) { - if ( strpos( $key, 'gtmkit_' ) === 0 ) { - unset( $item_data[ $key ] ); - } - } - - return $item_data; - } - /** * Registers the actual data into each endpoint. */ diff --git a/src/js/woocommerce.js b/src/js/woocommerce.js index d858757..feeb3d4 100644 --- a/src/js/woocommerce.js +++ b/src/js/woocommerce.js @@ -86,7 +86,7 @@ function gtmkitLoad() { ) ) { event = 'add_to_cart'; - } else if ( + } else if ( window.gtmkit_settings.wc.wishlist && (eventTargetElement.closest('.products') || eventTargetElement.closest('.wc-block-grid__products')) && eventTargetElement.closest( @@ -148,7 +148,7 @@ function gtmkitLoad() { if ( formCartElement ) { if ( eventTargetElement.closest( '.single_add_to_cart_button:not(.disabled,.input-needed)' ) ) { event = 'add_to_cart'; - } else if ( eventTargetElement.closest( window.gtmkit_settings.wc.css_selectors.single_product_wishlist ) ) { + } else if ( window.gtmkit_settings.wc.wishlist && eventTargetElement.closest( window.gtmkit_settings.wc.css_selectors.single_product_wishlist ) ) { event = 'add_to_wishlist'; } else { return true;