WooCommerce REST API - Filter Orders By Date Modified
This worked for me. Tested with Woo 4.0.x / API v3
add_filter('woocommerce_rest_orders_prepare_object_query', function(array $args, \WP_REST_Request $request) { $modified_after = $request->get_param('modified_after'); if (!$modified_after) { return $args; } $args['date_query'][0]['column'] = 'post_modified'; $args['date_query'][0]['after'] = $modified_after; return $args;}, 10, 2);
/wp-json/wc/v3/orders/?modified_after=2020-05-09T14:00:00
Hope it helps someone.
I've solved the problem with the following steps:
Create a folder.
Create a file with the same name and the following content:
<?php/** * Plugin Name: ModifyOrder */function modify_orders_after_query($request) { $request['date_query'][0]['column'] = 'post_modified'; return $request;}add_filter( "woocommerce_rest_orders_prepare_object_query", 'modify_orders_after_query' );
Drop it in the wp-content/plugins folder.
In the admin panel, you can see your folder name as a plugin,activate it and try!
This is working:
/wp-json/wc/v2/orders?after=2019-01-10T00:00:00Z&before=2019-01-10T23:59:59Z