We’re writing a WordPress plugin in which we retrieve Product/Order/Customer data from WooCommerce websites and storing it in our server, and incrementally updating it periodically for the changes. We’ve done this already for Products and Orders.
Now, we want to get the customer who updates their data after a specific date for the incremental update. I have tried it like below based on https://stackoverflow.com/a/64029143/698072. While it’s working for products and orders, it’s not working for customers.
add_filter('woocommerce_rest_customer_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);
Any help on this would be greatly appreciated.
2
Answers
In woocommerce, for products and orders, the last modified date is stored in
post_modified
column ofposts
table. But for customers, it’s stored in theusermeta
table with the key aslast_update
. So you have to filter it on the meta data like this,For products and orders, you can retrieve it like this, WooCommerce REST API v3 – Filter products by modified date using
woocommerce_rest_product_object_query
filter.The prior answer was crashing on my environment so, in case someone need an alternative solution, here it is: