{"action":"created","issue":{"url":"https://api.github.com/repos/woocommerce/woocommerce/issues/20105","repository_url":"https://api.github.com/repos/woocommerce/woocommerce","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/20105/labels{/name}","comments_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/20105/comments","events_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/20105/events","html_url":"https://github.com/woocommerce/woocommerce/issues/20105","id":323839940,"number":20105,"title":"GDPR: Add ability to filter orders affected by anonymize_orders_query() and trash_orders_query()","user":{"login":"james-allan","id":8490476,"avatar_url":"https://avatars0.githubusercontent.com/u/8490476?v=4","gravatar_id":"","url":"https://api.github.com/users/james-allan","html_url":"https://github.com/james-allan","followers_url":"https://api.github.com/users/james-allan/followers","following_url":"https://api.github.com/users/james-allan/following{/other_user}","gists_url":"https://api.github.com/users/james-allan/gists{/gist_id}","starred_url":"https://api.github.com/users/james-allan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/james-allan/subscriptions","organizations_url":"https://api.github.com/users/james-allan/orgs","repos_url":"https://api.github.com/users/james-allan/repos","events_url":"https://api.github.com/users/james-allan/events{/privacy}","received_events_url":"https://api.github.com/users/james-allan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/woocommerce/woocommerce/milestones/98","html_url":"https://github.com/woocommerce/woocommerce/milestone/98","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/milestones/98/labels","id":2747692,"number":98,"title":"3.4.0","description":"","creator":{"login":"mikejolley","id":90977,"avatar_url":"https://avatars2.githubusercontent.com/u/90977?v=4","gravatar_id":"","url":"https://api.github.com/users/mikejolley","html_url":"https://github.com/mikejolley","followers_url":"https://api.github.com/users/mikejolley/followers","following_url":"https://api.github.com/users/mikejolley/following{/other_user}","gists_url":"https://api.github.com/users/mikejolley/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejolley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejolley/subscriptions","organizations_url":"https://api.github.com/users/mikejolley/orgs","repos_url":"https://api.github.com/users/mikejolley/repos","events_url":"https://api.github.com/users/mikejolley/events{/privacy}","received_events_url":"https://api.github.com/users/mikejolley/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":370,"state":"open","created_at":"2017-09-06T10:44:46Z","updated_at":"2018-05-18T11:31:10Z","due_on":"2018-05-23T07:00:00Z","closed_at":null},"comments":2,"created_at":"2018-05-17T01:19:33Z","updated_at":"2018-05-18T13:12:33Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"The [settings](https://cloudup.com/cwmrI0hUFlA) coming in 3.4 which allow store managers to specify how long certain orders should live for before being trashed/anonymised and the events which carry those requests out aren't currently filterable. \r\n\r\nFrom a Subscriptions point of view, we don't want renewal orders (and other subscription-related order types) to be trashed or anonymised while the subscription is still live.\r\n\r\nTrashing or anonymised subscription orders could cause issues with subscription date calculation as it would cause incorrect completed payment counts for example. \r\n\r\n**Describe the solution you'd like**\r\nA filter to allow third-parties to customise what orders can be affected by [`WC_Privacy ::anonymize_orders_query()`](https://github.com/woocommerce/woocommerce/blob/3.4.0-rc.1/includes/class-wc-privacy.php#L267) and [`WC_Privacy::trash_orders_query()`](https://github.com/woocommerce/woocommerce/blob/3.4.0-rc.1/includes/class-wc-privacy.php#L224) similar to the [`'woocommerce_privacy_erase_order_personal_data'`](https://github.com/woocommerce/woocommerce/blob/3.4.0-rc.1/includes/class-wc-privacy-erasers.php#L134) filter.\r\n\r\n**Describe alternatives you've considered**\r\n\r\n- Adding a filter [here](https://github.com/woocommerce/woocommerce/blob/3.4.0-rc.1/includes/class-wc-privacy.php#L273) and [here](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-privacy.php#L230) to allow third-parties to prevent an order from being trashed or anonymised. \r\n- Adding a filter [here](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-privacy.php#L268) and [here](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-privacy.php#L225) to allow third-parties to add their own query args to limit the query. \r\n\r\nBoth of those possible fixes ran into problems though. The first filter option causes issues because if an order was skipped the `$count` variable would be incorrect and then cause [this condition](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-privacy-background-process.php#L63) to pass incorrectly. We could still increment the `$count` variable if an order is skipped, but then we run into a new problem, if the number of skipped orders is more than the `$limit` (20). The next time the `wc_get_orders( $query )` runs, it will return a full batch of ignored orders. \r\n\r\nThis is where I considered a filter to filter the `$query` arg. This would allow third-parties to prevent their order types from being considered at all, however from a Subscriptions point of view, there are some subscription order types which couldn't be excluded using the `wc_get_orders()` `$query`. For example subscription parent orders (initial purchase orders) are only set as the subscription post parent, they don't have any meta or anything that we could use to filter those out.\r\n\r\nLet me know if you have any ideas on ways we might be able to resolve this. \r\n\r\nRegarding any concerns you have with Subscriptions effectively ignoring these settings, we're going to  make it clear to store managers that this is the case with a note in the setting description. We're also planning on adding similar settings for subscriptions which would essentially anonymise the subscription and all it's related orders after the subscription has ended etc."},"comment":{"url":"https://api.github.com/repos/woocommerce/woocommerce/issues/comments/390202457","html_url":"https://github.com/woocommerce/woocommerce/issues/20105#issuecomment-390202457","issue_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/20105","id":390202457,"user":{"login":"james-allan","id":8490476,"avatar_url":"https://avatars0.githubusercontent.com/u/8490476?v=4","gravatar_id":"","url":"https://api.github.com/users/james-allan","html_url":"https://github.com/james-allan","followers_url":"https://api.github.com/users/james-allan/followers","following_url":"https://api.github.com/users/james-allan/following{/other_user}","gists_url":"https://api.github.com/users/james-allan/gists{/gist_id}","starred_url":"https://api.github.com/users/james-allan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/james-allan/subscriptions","organizations_url":"https://api.github.com/users/james-allan/orgs","repos_url":"https://api.github.com/users/james-allan/repos","events_url":"https://api.github.com/users/james-allan/events{/privacy}","received_events_url":"https://api.github.com/users/james-allan/received_events","type":"User","site_admin":false},"created_at":"2018-05-18T13:12:33Z","updated_at":"2018-05-18T13:12:33Z","author_association":"CONTRIBUTOR","body":"> Your PR removes the limits which will make that query so much slower.\r\n\r\nYeah that's fair. The issue with just filtering the queries is that we can't exclude all subscription order types just with `wc_get_order()` args. By order type I don't mean post type (`shop_order` or `shop_subscription`), I mean like renewal, switch and parent orders. All those orders are `'shop_orders'` so it's not a matter specifying the type arg. \r\n\r\nRenewal and switch orders have `_subscription_renewal` and `_subscription_switch` post meta so theoretically we can exclude those by filtering the query but subscription parent orders are the post parent of a subscription post. As far as I can tell it's not possible to exclude those by filtering `wc_get_order()` args.\r\n\r\nLet me know what you think though, if you see a way we could do it, I would be happy to go with it."}}
{"actor":{"display_login":"james-allan"}}