* Description: Fast zone-scoped master order list for rushlane-admin. Tags orders with _rl_delivery_zone_id and queries via WCFM vendor zone index (SQL) instead of scanning WooCommerce pages.
* GET /wp-json/rushlane/v1/admin/orders-by-zone?zone_id=williamnagar&page=1&per_page=20
function rushlane_admin_orders_zone_list( WP_REST_Request $request ) {
if ( ! function_exists( 'wc_get_order' ) ) {
$zone_id = sanitize_key( (string) $request->get_param( 'zone_id' ) );
if ( '' === $zone_id || 'all' === $zone_id ) {
return new WP_Error( 'missing_zone', 'zone_id is required', array( 'status' => 400 ) );
}
$page = max( 1, (int) $request->get_param( 'page' ) );
$per_page = min( 50, max( 1, (int) $request->get_param( 'per_page' ) ) );
$result = rushlane_admin_orders_zone_query_ids(
$zone_id,
array(
'page' => $page,
'per_page' => $per_page,
'store_id' => (int) $request->get_param( 'store_id' ),
'status' => (string) $request->get_param( 'status' ),
'search' => (string) $request->get_param( 'search' ),
'after' => (string) $request->get_param( 'after' ),
'before' => (string) $request->get_param( 'before' ),
)
);
$orders = array();
foreach ( $result['ids'] as $oid ) {
$order = wc_get_order( $oid );
if ( ! $order instanceof WC_Order ) {
continue;
}
// Avoid save() during list — tagging on checkout is enough for speed.
$row = rushlane_admin_orders_zone_serialize( $order );
if ( empty( $row['zone_id'] ) ) {
$row['zone_id'] = $zone_id;
}
$orders[] = $row;
}
$zones = array();
if ( function_exists( 'rushlane_get_delivery_zones' ) ) {
foreach ( rushlane_get_delivery_zones( false ) as $z ) {
$zid = sanitize_key( (string) ( $z['zone_id'] ?? '' ) );
if ( '' === $zid ) {
$zones[] = array(
'id' => $zid,
'label' => (string) ( $z['name'] ?? $zid ),
);
$total = (int) $result['total'];
$total_pages = max( 1, (int) ceil( max( 1, $total ) / $per_page ) );
'zones' => $zones,
'source' => 'rushlane-admin-orders-zone',
'debug' => array(
'zone_id' => $zone_id,
'vendor_count' => (int) ( $result['vendor_count'] ?? 0 ),
'candidate_count' => (int) ( $result['candidate_count'] ?? 0 ),
),
register_rest_route(
'rushlane/v1',
'/admin/orders-by-zone',
array(
'methods' => 'GET',
'callback' => 'rushlane_admin_orders_zone_list',
'permission_callback' => 'rushlane_admin_orders_zone_permission',
'args' => array(
'zone_id' => array(
'required' => true,
'sanitize_callback' => 'sanitize_key',
),
'page' => array(
'default' => 1,
'sanitize_callback' => 'absint',
),
'per_page' => array(
'default' => 20,
'sanitize_callback' => 'absint',
),
'store_id' => array(
'default' => 0,
'sanitize_callback' => 'absint',
),
'status' => array(
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
),
'search' => array(
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
),
'after' => array(
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
),
'before' => array(
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
),
cant the fetch find another solution insted of scanning all orders find new api for short cut with mu plugin also fetch all teh api it will over laod api calls
const dateTo = request.nextUrl.searchParams.get("dateTo")?.trim() || "";
// Client already has stores/drivers/zones — skip expensive meta refetch.
const ordersOnly = request.nextUrl.searchParams.get("ordersOnly") === "1";
const pagination = (data.pagination || {}) as AnyObj;
const zonesRaw = Array.isArray(data.zones) ? data.zones : [];
const zonesMerged = mergeZoneCenters(
zonesRaw
if (dateTo) qs.set("dateTo", dateTo);
// After first full load, only refetch orders (stores/drivers/zones stay cached client-side).
// One WP master-orders call. After first load, skip meta (stores/drivers/zones).
// Zone change always refreshes store list for that zone.
* Plugin Name: Rushlane admin orders by zone
* Description: Fast zone-scoped master order list for rushlane-admin. Tags orders with _rl_delivery_zone_id and queries via WCFM vendor zone index (SQL) instead of scanning WooCommerce pages.
* Description: Single shortcut API for rushlane-admin master orders. Uses WCFM SQL + zone index (no WooCommerce REST scanning / fan-out).
*
if ( '' !== $zone_id && 'all' !== $zone_id ) {
$stores = rushlane_admin_master_store_rows( rushlane_admin_orders_zone_vendor_ids( $zone_id ) );
// Index only (no per-request GPS crawl of all vendors).
$zone_vendor_ids = function_exists( 'rushlane_vendors_in_zone' )
Yes — that’s the right approach. It’s now one shortcut API, not many WooCommerce scans.
Upload this file again wp-content/mu-plugins/rushlane-admin-orders-zone.php
New endpoint (single call) GET /wp-json/rushlane/v1/admin/master-orders
Returns in one response:
orders (SQL via WCFM / zone index — no scanning all WC orders)
zone-scoped stores
zones, statuses, drivers
Admin side
Calls only that one WP endpoint
Does not fan out to store-vendors × pages, driver roles × 3, vendors-in-zone, etc.
Later page/filter changes use ordersOnly=1 so meta isn’t refetched
Filtering
Filter Method
Zone
WCFM + zone index SQL
Store
WCFM vendor_id SQL
None
Native wc_get_orders (1 query)
No more multi-page WooCommerce order scanning. After you upload the mu-plugin, reload Master orders and it should stay light on the API.
Agent