-
-
Notifications
You must be signed in to change notification settings - Fork 109
Feature/ajax cart improvements #1120
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
Conversation
Added the .remove class to the button to work with the js that gtm4wp is using. as the class is also present in the storefront theme i assume that could add compatibility to other plugins as well. Ovewrites to some woocommerce css classes had to be done to keep the original styling
Moves the `force_fragments_refresh` check to the top of the success function, and allows it to trigger even on unsuccessful responses as well.
The previous implementation of the quantity update triggered events before the cart fragments were fully updated because startViewTransition runs asynchronously. Therefore the update events where moved to run always after the updates of the cart happen.
Separates the cart item removal logic from the quantity update logic. This improves code clarity and addresses potential issues with plugins that modify the cart after quantity changes. Handles cases where plugins might remove or alter cart items after a quantity update, ensuring correct cart behavior and fragment updates. Also fixes a bug where the max quantity check was performed when removing items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the AJAX cart functionality to fix timing issues with quantity update events on modern browsers and improves compatibility with GTM4WP tracking. The key changes move event triggers into the updateCartFragments function to handle asynchronous execution properly when using startViewTransition, and consolidate cart item removal logic to use the same code path as quantity updates.
Key Changes:
- Fixed premature
qty_updatedevent firing by moving event triggers intoupdateCartFragmentsto handle async execution withstartViewTransition - Refactored quantity update to handle removal (qty=0) within the same function instead of separate logic paths
- Added "remove" CSS class to cart item remove button for GTM4WP compatibility
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| woocommerce/js/ajax-cart.js | Restructured success/failure handling and moved event triggers into updateCartFragments to fix async timing issues |
| woocommerce/inc/ajax-cart.php | Consolidated removal logic into quantity update function, added WPML compatibility check, and adjusted notice types |
| woocommerce/cart/mini-cart-item.php | Added "remove" class to remove button for GTM4WP tracking compatibility |
| assets/scss/bootscore-woocommerce/_wc-ajax-cart.scss | Added styles to reset WooCommerce default remove button appearance |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crftwrk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merci 🙏
Closes #1061