liquidweb / woocommerce-custom-orders-table

Store WooCommerce order data in a custom table for improved performance.
GNU General Public License v3.0
476 stars 51 forks source link

WIP PoC for the removal when wp_delete_post is used. #167

Closed juliquiron closed 2 years ago

juliquiron commented 4 years ago

This PR fixes https://github.com/liquidweb/woocommerce-custom-orders-table/issues/111

Description of the problem.

Operations like bulk operations delete with a direct URL or maybe others can directly use wp_delete_post function. In these cases, the order is properly deleted from the posts table but not of the woocommerce_orders one because no data-store is being used in the whole operation.

How does it work in WooCommerce

WooCommerce manage the extra 'order' data in the before_delete_post filter, see: https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-post-data.php#L388

Proposed solution

Register the delete_post filter to perform the delete operation in the custom table.

This has an open question, is that when the data-store is used it calls the parent delete, can it create a loop? I don't test it, with the PR we are going to see the tests which are testing so. Also, maybe then the datastore can just delete the post and let the filter act to clear the custom table, but I don't want to modify also this without feedback.