Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
87 stars 33 forks source link

Refactor and update the admin subscription bulk action handling to support HPOS environments #367

Closed james-allan closed 1 year ago

james-allan commented 1 year ago

Fixes #364 Fixes #320 Fixes #301

Description

On HPOS environments, admin bulk actions and subscription action links were erroring or redirecting to the orders table. There were a few different issues that this PR addresses.

  1. On HPOS WC expects third parties to hook onto the dynamic hook handle_bulk_actions-{woocommerce_page_wc-orders--shop_subscription} to tell it which page to redirect to after processing bulk actions. This PR does that.
    • 320

  2. For the individual subscription actions, WC changed the nonce flag (from the default WP one bulk-posts to bulk-orders). This change in nonce resulted in the The link you followed has expired errors.
    • 364

This PR fixes both those issues and includes some general tidying of the relevant code.

How to test this PR

  1. Enable HPOS.
  2. Purchase at least 1 subscription.
  3. Go to WooCommerce > Subscriptions on admin
  4. Select at least 1 subscription, and choose a bulk action from the dropdown.
  5. Click apply.
  6. The selected subscriptions should be updated.
  7. A notice should appear explaining the number of subscriptions updated.
  8. Hover over individual subscription and click one of the action links (suspend, activate, cancel etc)
  9. The relevant subscription should be updated.
  10. A notice should appear explaining the number of subscriptions updated.
  11. Repeat for CPT.
Screen Shot 2023-01-11 at 10 14 11 am Screen Shot 2023-01-11 at 10 19 32 am

Product impact

james-allan commented 1 year ago

Trash a subscription ❌ Untrash all trashed subscriptions ❌ Delete permanently :x: Cancel and remove personal data ❌

I've fixed this with c97db78.

Turns out I wasn't returning out of parse_bulk_actions() when processing actions that are handled by WC or WP core.

mattallan commented 1 year ago

I've tested the latest changes and confirmed it's fixed the issues I found. There's still one issue remaining with fixing "Cancel and remove personal data" bulk action on stores with HPOS but I've created a separate issue for this as it'll require some bigger changes