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
Enable High-performance order storage on your store (found: WC > Settings > Advanced > Features)
Create a throw-away user by going to WP Admin > Users > Add New
Create the user with the minimum details i.e. customer1 customer1@example.com and default password
Go to WC > Subscriptions > Add New
Create a basic subscription for this new customer and use the actions drop-down to create a pending parent order.
Go to WP Admin > Users and delete the user.
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.
On this branch the subscription will be removed.
Product impact
[x] Added changelog entry (or does not apply)
[x] Will this PR affect WooCommerce Subscriptions? yes
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 usingwp_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 thewp_post_delete( $id )
method with$subscription->delete( true )
so work in both HPOS & WP Posts environments.How to test this PR
trunk
you will notice the subscription still exists without a customer and the parent order will have a note saying the subscription was deleted.Product impact