Skip to content

Commit

Permalink
Improve the support for the select_item events in more themes
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Dec 30, 2023
1 parent c2cda82 commit f73fd64
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/integration/woocommerce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1
#### Enhancements:
* Add support for Google Consent Mode v2
* Added a function to share system data with the GTM Kit support team. If you have registered a support request on WordPress.org and the GTM Kit support team has asked you to send your system data you can now do that in a secure way without posting any private information in the support forum.
* Enhanced support for the select_item event in more WordPress themes. This update significantly improves the compatibility of the select_item event handling in themes such as Woodmart.

#### Bugfixes:
* When adding a product to the cart from a product category page the quantity was not specified in the add_to_cart event.
Expand Down
8 changes: 4 additions & 4 deletions src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ function gtmkitLoad() {
productsInGroup.forEach(function (productData) {
let productQuantity = document.querySelectorAll(
'input[name=quantity\\[' +
productData.getAttribute('data-gtmkit_product_id') +
'\\]]'
productData.getAttribute('data-gtmkit_product_id') +
'\\]]'
);

productQuantity = Number(productQuantity[0].value);
Expand Down Expand Up @@ -287,7 +287,7 @@ function gtmkitLoad() {

// select_item event on clicks in product lists
const productListItemSelector =
'.products li:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist,.tinvwl_add_to_wishlist_button),' +
'.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)';
document.addEventListener('click', function (e) {
Expand Down Expand Up @@ -344,7 +344,7 @@ function gtmkitLoad() {

const productVariationData = JSON.parse(
variationsForm.querySelector('[name=gtmkit_product_data]') &&
variationsForm.querySelector('[name=gtmkit_product_data]').value
variationsForm.querySelector('[name=gtmkit_product_data]').value
);

productVariationData.id = productVariationData.item_id =
Expand Down

0 comments on commit f73fd64

Please sign in to comment.