Automattic / woocommerce-subscriptions-core

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

[HPOS] Replace remaining delete post code in subscriptions to use CRUD methods/hooks #365

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Description

This PR replaces the remaining wp_delete_post() function calls and deleted_post hooks that was interacting with Subscription objects.

These instances have all been replaced with the $subscription->delete() equivalent and woocommerce_delete_subscription hooks.

How to test this PR

Code review should be sufficient here, however, to test these changes:

  1. Purchase a downloadable subscription product.
  2. Check the woocommerce_downloadable_product_permissions table for a row with the subscription ID in the order_id column
  3. Run the following snippet below to force delete a subscription
  4. Confirm the download permissions have also been removed.
$subscription = wcs_get_subscription( 123 );
$subscription->delete( true );

Product impact