One of the great mysteries of life is why the WooCommerce API does not support a way to query orders by last modified date – even though this feature is a must-have for many ERP integrations.
Fortunately, it’s quite easy to implement:
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);
The query param is modified_after and it accepts an ISO8601 compliant date just like the rest of Woo API:
/wp-json/wc/v3/orders/?modified_after=2020-05-09T14:00:00
Tested with Woo 4.0.x / API v3.
2 Responses to “Filtering by last modified date in WooCommerce API”
Ken Loveless
Wow! Thanks! This works for created_after as well. Works for Products and Orders. Can’t seem to make it work for Customers.
Justin
Excellent information! This is exactly what I was looking for and a quick google led me to your site. Thanks so much.