Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trash_users_subscriptions() to properly delete subscriptions in HPOS environments. #520

Merged
merged 4 commits into from
Oct 6, 2023

Conversation

mattallan
Copy link
Contributor

Description

When a user/subscriber is deleted, we hook onto the delete_user hook and delete all subscriptions that belong to this user. This function was still using wp_post_delete() which doesn't work in a HPOS environment resulting in subscriptions remaining without a customer attached.

This PR updates the trash_users_subscriptions() function and replaces the wp_post_delete( $id ) method with $subscription->delete( true ) so work in both HPOS & WP Posts environments.

How to test this PR

  1. Enable High-performance order storage on your store (found: WC > Settings > Advanced > Features)
  2. Create a throw-away user by going to WP Admin > Users > Add New
  3. Create the user with the minimum details i.e. customer1 [email protected] and default password
  4. Go to WC > Subscriptions > Add New
  5. Create a basic subscription for this new customer and use the actions drop-down to create a pending parent order.
  6. Go to WP Admin > Users and delete the user.
  7. On trunk you will notice the subscription still exists without a customer and the parent order will have a note saying the subscription was deleted.
  8. On this branch the subscription will be removed.

Product impact

  • Added changelog entry (or does not apply)
  • Will this PR affect WooCommerce Subscriptions? yes
  • Will this PR affect WooCommerce Payments? yes

Copy link
Contributor

@james-allan james-allan left a comment

Choose a reason for hiding this comment

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

Changes look good to me and work as described.

I replicated the issue on trunk - the customer subscriptions remained after I deleted the user.

I confirmed this also works while syncing is enabled (it deletes in both tables) with both HPOS and WP Posts tables.

  • HPOS - no syncing
  • HPOS - with syncing
  • WP Posts - no syncing
  • WP Posts - with syncing

@mattallan mattallan merged commit d972919 into trunk Oct 6, 2023
12 checks passed
@mattallan mattallan deleted the fix/hpos-trash-users-subscriptions branch October 6, 2023 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants