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.
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.
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 theposts
table but not of thewoocommerce_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#L388Proposed 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.