Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Fix empty error notices on the My Account > Payment Methods page when the store uses block based notices #571

Closed james-allan closed 4 months ago

james-allan commented 4 months ago

Fixes https://github.com/woocommerce/woocommerce-subscriptions/issues/4616

Description

If you attempted to delete a token that was used by an active subscription, there was no default set and you used a block based checkout, you'd be faced with this empty error message.

Screenshot 2024-02-14 at 1 02 46 pm

The issue here was caused by the way we display this notice. We print an empty notice to the screen and hide it (WCS_My_Account_Payment_Methods::print_deleting_notices()). If the user clicks on one of the delete token buttons that we've altered to instead result in an error, we populate the empty notice with the correct error message and then show the notice.

The problem was that block based stores use a slightly different notice HTML and so populating the notice with the content didn't work.

This PR updates the JS code to make sure it can support block based notices format and old WC notices.

How to test this PR

WC 8.4+

  1. Make sure you're running WC 8.5 and above.
  2. Purchase a subscription using a saved token or add a new one.
  3. Go to the My Account > Payment methods screen
  4. Attempt to delete the token.
    • trunk You should see the blank notice above.
    • On this branch the notice should be populated with the correct content.
trunk This branch
Screenshot 2024-02-14 at 2 05 16 pm Screenshot 2024-02-14 at 2 08 06 pm

WC 8.4

  1. Install WC 8.4 from here: https://github.com/woocommerce/woocommerce/releases/tag/8.4.0
  2. Repeat steps above.
  3. On trunk and this branch, the notice works fine.
Screenshot 2024-02-14 at 2 05 33 pm

Product impact