woocommerce / woocommerce-google-analytics-integration

WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
http://wordpress.org/plugins/woocommerce-google-analytics-integration/
170 stars 69 forks source link

Add checks and explicit errors when cart buttons are missing data #443

Closed tomalec closed 2 months ago

tomalec commented 2 months ago

Changes proposed in this Pull Request:

Add checks and explicit errors when cart buttons are missing data to help debugging issues with other extensions manipulating WC Core add & remove from cart buttons or events.

This would help identifying issues like the one reported at https://wordpress.org/support/topic/js-error-on-add-to-cart-when-logged-out/

Checks:

Screenshots:

image

Detailed test instructions:

  1. Build the branch
  2. open shop page
  3. Run synthetic/malformed cart events
    jQuery( document.body ).trigger( 'added_to_cart' );
    jQuery( document.body ).trigger( 'removed_from_cart' );
  4. Check for errors in the console
  5. Add an item to the cart using UI.
  6. Remove all product ids document.querySelectorAll('[data-product_id]').forEach((e)=>e.removeAttribute('data-product_id')). 8. Remove item from mini cart using UI
  7. Check for errors in the console
  8. Smoke test not tempered events and buttons for adding to & removing from cart, for regression

Additional details:

Changelog entry

Tweak - Add checks and explicit errors when cart buttons are missing data.

tomalec commented 2 months ago

Thanks @eason9487 for the detailed review :)