Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent firing up the add_to_cart event when clicking in product image #332

Merged

Conversation

jorgemd24
Copy link
Contributor

@jorgemd24 jorgemd24 commented Nov 24, 2023

Changes proposed in this Pull Request:

Closes #330

With non-blockified themes, the add_to_cart event's selector is quite broad, leading it to trigger even when a user clicks on the product image.

$( '.product.post-" . esc_js( $product->get_id() ) . ' a , .product.post-' . esc_js( $product->get_id() ) . " button' ).on('click', function() {

This PR makes the selector more specific, checking that the link needs to have the class button.

Checks:

  • Does your code follow the WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Screenshots:

Detailed test instructions:

  1. Use a non-blockified theme, for example store front.
  2. Setup the extension with your Google Analytics Tracking ID.
  3. Enable all the options of "Enable Enhanced eCommerce" in /wp-admin/admin.php?page=wc-settings&tab=integration&section=google_analytics
  4. Install the Google Analytics Chrome extension or use the https://tagassistant.google.com/ to see the events.
  5. Open an incognito mode, go to the shop and click the product image. See that the event add_to_cart is not sent.

Additional details:

  • PHP unit tests failed but they are fixed here: Update phpunit polyfills to 1.1 #333. Local tests passes if you run composer require --dev yoast/phpunit-polyfills:"^1.1.0" && composer install

Changelog entry

Fix - Prevent firing up the add_to_cart event when clicking in product image

@jorgemd24 jorgemd24 self-assigned this Nov 24, 2023
@github-actions github-actions bot added changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug. labels Nov 24, 2023
@jorgemd24 jorgemd24 requested a review from a team November 24, 2023 13:15
Copy link
Contributor

@martynmjones martynmjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jorgemd24, thanks for your work on this issue.

Tested locally and can confirm the add_to_cart event is only triggered when clicking the add to cart button and unit tests are passing after upgrading the polyfills package so LGTM ✅

@jorgemd24 jorgemd24 merged commit 6ad1eb8 into trunk Nov 27, 2023
5 of 7 checks passed
@jorgemd24 jorgemd24 deleted the fix/330-add-to-cart-event-fired-up-when-clicking-image branch November 27, 2023 16:36
@tomalec tomalec mentioned this pull request Nov 28, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add to cart event is fired up when clicking on a product to see details
2 participants