John Davidson

php - WooCommerce REST API v3 - Filter customers by modified date

0 comments
Message:


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.



My Answer:
>get_param('modified_after');
if ($modified_after) {
$args['date_modified'] = '>=' . date('Y-m-d H:i:s', strtotime($modified_after));
}
return $args;
}, 10, 2);

This code snippet adds a filter to the WooCommerce REST API customer query to filter customers based on their modified date. The 'modified_after' parameter is retrieved from the request and used to filter customers whose modification date is greater than or equal to the specified date.

Make sure to include this code in your WordPress plugin file where you are interacting with the WooCommerce REST API. This should help you filter customers based on their modified date for incremental updates.

Rate this post

5 of 5 based on 5163 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us