Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Axos11
Copy link
Contributor

@Axos11 Axos11 commented Oct 25, 2025

  • Refactors cart quantity update and removal logic
  • Fixes qty_update events fired to early on modern browsers
  • Added compatibility with gtm4wp removal action beeing tracked.

Closes #1061

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.
@Axos11 Axos11 requested review from Copilot and crftwrk October 25, 2025 09:00
Copy link

Copilot AI left a 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_updated event firing by moving event triggers into updateCartFragments to handle async execution with startViewTransition
  • 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 crftwrk added this to v6.4.0 Oct 25, 2025
@crftwrk crftwrk moved this to In Progress in v6.4.0 Oct 25, 2025
Copy link
Member

@crftwrk crftwrk left a comment

Choose a reason for hiding this comment

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

Merci 🙏

@Axos11 Axos11 merged commit 728909c into main Oct 25, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in v6.4.0 Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Mini Cart - Unable to Remove Out-of-Stock Product

3 participants