How to create WordPress custom end point with multiple parameters?
-
Hi,
I want to get all WooCommerce orders from given date range. I can retrieve all orders at once. But I am confusing with passing the date range via API URL.Can anybody help me with this? I know it’s something like this but can’t figure out the exact way to do it.
Here is my route:
add_action('rest_api_init', function() { register_rest_route('woo/v2', 'woocommerce/order_summary_by_date/(?P<start_date>/<end_date>)', array( 'methods' => 'GET', 'callback' => 'woocommerce_orders_by_dates' )); });
This is the function to access:
function woocommerce_orders_by_dates($start_date, $end_date) { $start_date = $start_date['start_date']; $end_date = $end_date['start_date']; return $start_date . $end_date; }
URL is:
https://example.com/wp-json/woo/v2/woocommerce/order_summary_by_date/?start_date=2021-09-01&end_date=2021-09-30
Any help highly appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to create WordPress custom end point with multiple parameters?’ is closed to new replies.