-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[HPOS] Add hooks that fire before an order is trashed/deleted. #34858
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
Conversation
New hooks are: 1. `woocommerce_before_delete_order` 2. `woocommerce_before_trash_order`
Test Results SummaryCommit SHA: 6957745
To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
|
✍🏽 E2E fails seem unrelated and are being investigated. Internal link: p1664377590875839-slack-C01BWDDTGKX |
jorgeatorres
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM 👍. Thanks @barryhughes!
One question, though: what are your thoughts on adding these hooks to the CPT datastore too? It might help with compatibility.
That's a good question 🤔 It probably would be helpful, since then only one hook is needed, but for them to be truly equivalent I think we would need to hook into the equivalent WordPress actions, such as (illustrative only): add_action(
'delete_post',
function( $post_id, $post ) {
if ( in_array( $post->post_type, wc_get_order_types(), true ) ) {
do_action( 'woocommerce_before_delete_order', $post_id, $post );
}
},
10,
2
);(Because if we modify I think that would probably work ... but we'd need to make it crystal clear that the hook is fired from both locations. Otherwise, a plugin author might add Perhaps a way to mitigate this would be to supply a third parameter, which would be the data-store class. wdyt @jorgeatorres? |
|
Or perhaps we don't add duplicate hooks for the CPT data-store, but rename these two new hooks to something like:
|
This looks ok, but then you'd receive a post instead of an order, unless we load the order again at this point, which I'm not sure we should be doing.
Yep, I didn't think of
I'm thinking this is probably going to be the case, so even though I would've preferred that some canonical actions are always called (instead of depending on the datastore), your current implementation is probably what makes the most sense in the spirit of not breaking existing code. If we receive requests to add the same hook to the posts datastore, we might think about doing something more clever (including not firing both Given the above, I'm going to merge this as-is, but we can always iterate later. Do let me know if you feel otherwise! |
|
Hi @jorgeatorres, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
|
Thanks: sounds like a plan—as you say, we can always iterate further as adoption of HPOS grows and we get more data 👍 |
New hooks are:
woocommerce_before_delete_orderwoocommerce_before_trash_orderThese fire immediately before an (HPOS) order is deleted or trashed, and act as analogs to
delete_postandwp_trash_postin the case of CPT objects.Closes #34231.
How to test the changes in this Pull Request:
It should be sufficient to review the code, there are no functional differences (since there is no code within core that uses these new actions).
FOR PR REVIEWER ONLY: