Skip to content

Commit

Permalink
Add flexible product list selector
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Sep 27, 2024
1 parent 6a1ec1a commit da39300
Show file tree
Hide file tree
Showing 3 changed files with 11 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.

6 changes: 4 additions & 2 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ public function get_global_settings( array $global_settings ): array {
];
$global_settings['wc']['css_selectors'] = [
'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)',
'.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)',
'product_list_element' => '.product,.wc-block-grid__product',
'product_list_exclude' => '',
];

return $global_settings;
Expand Down
8 changes: 6 additions & 2 deletions src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function gtmkitLoad() {
}

const productElement = eventTargetElement.closest(
'.product,.wc-block-grid__product'
window.gtmkit_settings.wc.css_selectors.product_list_element
);
const productData =
productElement &&
Expand Down Expand Up @@ -292,8 +292,12 @@ function gtmkitLoad() {
const linkElement = eventTargetElement.closest( window.gtmkit_settings.wc.css_selectors.product_list_select_item );
if (!linkElement) return true;

if ( window.gtmkit_settings.wc.css_selectors.product_list_exclude && linkElement.closest(window.gtmkit_settings.wc.css_selectors.product_list_exclude)) {
return true;
}

const product = eventTargetElement.closest(
'.product,.wc-block-grid__product'
window.gtmkit_settings.wc.css_selectors.product_list_element
);

let productData;
Expand Down

0 comments on commit da39300

Please sign in to comment.