1
votes

I'm looking for a way to get a list of orders that are updated after a certain specified date. I'm using the Woocommerce REST API to access these orders. In the API docs I find there is a 'after' parameter on a GET call, but this only filters for orders published after a certain date, not updated.

Thanks a lot!

2

2 Answers

1
votes

Updated Answer:
Add the following code in a custom plugin.

function modify_orders_after_query($request) {
    $request['date_query'][0]['column'] = 'post_modified';
    return $request;
}

add_filter( "woocommerce_rest_shop_order_query", 'modify_orders_after_query' );

Then you can make GET request to your API url, Something like this:
http://example.com/wp-json/wc/v1/orders?after=2016-10-10T10:10:10Z

Notice: Please test before using this method.

Legacy:
This can be achieved with updated_at_min.
Please check wp-content\plugins\woocommerce\includes\api\class-wc-api-resource.php: Line 157 and wp-content\plugins\woocommerce\includes\api\class-wc-api-orders.php: Line 723

1
votes

I've managed to solve the problem using the tips from above. Added a folder with a file in plugin folder, with the same name and the following content:

<?php
/**
 * Plugin Name: wooCommerceFilter
 * Description: Change the ORDER API endpoint to consider date_modified.
 * Version: 1.0
 */

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' );


?>