Add WooCommerce 10.4+ Interactivity API Mini Cart compatibility#529
Add WooCommerce 10.4+ Interactivity API Mini Cart compatibility#529
Conversation
|
@lysyjan is this ready for review or waiting for more work? The CI is misleading, as the required PHP jobs won't start as there are no PHP changes, so you can ignore that (I'll try to take a look at how to configure this properly sometime this week). |
|
@NeosinneR I mentioned it in the Porter report, as I am not sure about the implementation at all. It was more like a quick exploration of the possible solution for why acceptance tests are failing with Woo 10.4+ |
|
@lysyjan does the plugin break in WooCommerce 10.4 without this change? 10.4 is aimed to be released tomorrow, but because the PR is in draft and no one is assigned, I don't see any action needed to be done by anyone. But this is the last week for plugin releases before holiday, so if this is needed, we should review, merge and release it ideally this week. If it's not required, it can wait, but it would be still good to know what are next steps with this PR. |
I don't think so. Based on the code, it looks like the tracking in the mini cart will stop working. I haven't found this issue during manual smoke tests. I can take a closer look later today, or you can check it manually. |
- Add click listener fallback for remove_from_cart event tracking - Add cart data fallback for begin_checkout event - Update tests for cross-version compatibility
4889dcb to
1f6f875
Compare
eason9487
left a comment
There was a problem hiding this comment.
Thanks for the work! I would like to clarify some conditions of logical branches.
In addition, thegetProductFromDOM function may not handle common price formats well.
I haven't further verified whether the data from JSON.parse( document.querySelector( '#wp-script-module-data-\\@wordpress\\/interactivity' ).innerText ) could replace some of the processing, but if not already considered, it might be a potential cart data source.
… lookup - Remove getProductFromInteractivityContext() which never worked (WooCommerce Mini Cart uses data-wp-each binding, not data-wp-context) - Add parsePriceFromDOM() using accounting.unformat() for proper handling of international price formats (e.g., "1.234,56 €") - Fix hardcoded currency_minor_unit (was always 2, now uses actual store settings from cart data or wcSettings.currency.precision) - Add getWcSettings() helper to reduce duplicate lookups - Add E2E tests for DOM fallback with US and European price formats
|
@eason9487 Thank you for your great review. I added a commit updating parsing prices and added an E2E test. I also removed redundant code and updated comments. |
eason9487
left a comment
There was a problem hiding this comment.
Thanks for the update!
There are still a few issues to resolve regarding the parsing of the price.
- Add currency settings (decimalSeparator, thousandSeparator, precision) to window.ga4w.settings from WooCommerce core functions - Simplify price parsing in blocks.js to use ga4w.settings.currency - Remove dependency on wcSettings and heuristic separator detection - Consolidate E2E tests for DOM fallback price parsing
|
I didn't know that |
eason9487
left a comment
There was a problem hiding this comment.
Thanks for the work! Tested several scenarios and all functioned normally.
Description
WooCommerce 10.4 introduces a new Mini Cart component built with the Interactivity API, replacing the previous React-based implementation. This change breaks two analytics tracking features:
remove_from_cartevent not firing - The new Mini Cart doesn't fire theexperimental__woocommerce_blocks-cart-remove-itemaction hookbegin_checkoutevent with empty cart data - The checkout hook fires before cart data is loaded from the Store APIChanges
Mini Cart removal tracking
Implemented a click event listener as a fallback for tracking item removals from the Interactivity API Mini Cart. The implementation uses multiple data sources with graceful fallbacks:
data-wp-contextattributes)wp.data.select('wc/store/cart'))window.ga4w.data.cart)A flag mechanism prevents duplicate events when the original hook does fire (for backwards compatibility with older WooCommerce versions).
Checkout event fallback
Added fallback to server-rendered cart data when the Store API cart data is empty or not yet loaded.
Testing
Requires WooCommerce 10.4.0 Beta 1 or later.
remove_from_cartevent should firebegin_checkoutevent should include cart itemsNote
This is a workaround for missing hook support in WooCommerce's new Interactivity API Mini Cart. Ideally, WooCommerce should fire the
experimental__woocommerce_blocks-cart-remove-itemaction for backwards compatibility.