Skip to content

Commit

Permalink
Fix bug on grouped products when using product ID prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Nov 30, 2023
1 parent 79c0653 commit d5b654b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 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.

2 changes: 1 addition & 1 deletion src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public function get_item_data_tag( WC_Product $product, string $item_list_name,

return sprintf(
'<span class="gtmkit_product_data" style="display:none; visibility:hidden;" data-gtmkit_product_id="%s" data-gtmkit_product_data="%s"></span>',
esc_attr( $this->prefix_item_id( $product->get_id() ) ),
esc_attr( $product->get_id() ),
esc_attr( wp_json_encode( $item_data ) )
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ function gtmkitLoad() {
productData.getAttribute('data-gtmkit_product_id') +
'\\]]'
);
productQuantity = parseInt(productQuantity[0].value);

if (0 === productQuantity) {
productQuantity = Number(productQuantity[0].value);
productQuantity = isNaN(productQuantity) ? 0 : productQuantity;

if (0 === productQuantity && event === 'add_to_cart') {
return true;
} else if (0 === productQuantity && event === 'add_to_wishlist') {
productQuantity = 1;
}

const itemData = JSON.parse(
Expand Down

0 comments on commit d5b654b

Please sign in to comment.