diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 0690b87..27e5fd7 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -28,7 +28,26 @@ class Order extends Processor { * @return integer */ public static function get_total( $plugin ) { - return (int) dokan()->order->all( [ 'return' => 'count', 'parent' => 0, ] ); + global $wpdb; + + switch ( $plugin ) { + case 'wcfmmarketplace': + $total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ); + break; + + case 'yithvendors': + $total = (int) dokan()->order->all( + [ + 'return' => 'count', + 'parent' => 0, + ] + ); + + default: + $total = 0; + } + + return $total; } /** @@ -41,6 +60,7 @@ public static function get_total( $plugin ) { * @throws \Exception */ public static function get_items( $plugin, $number, $offset ) { + global $wpdb; $args = array( 'order' => 'ASC', 'paged' => $offset + 1, @@ -48,7 +68,29 @@ public static function get_items( $plugin, $number, $offset ) { 'parent' => 0, ); - $orders = dokan()->order->all( $args ); + switch ( $plugin ) { + case 'wcfmmarketplace': + $orders = []; + $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET %d", $number, $offset ), ARRAY_A ); + $wcfm_orders = array_map( + function ( $item ) { + return $item['order_id']; + }, + $wcfm_orders + ); + + if ( ! empty( $wcfm_orders ) ) { + $orders = dokan()->order->all( + [ + 'include' => $wcfm_orders, + ] + ); + } + break; + + default: + $orders = []; + } if ( empty( $orders ) ) { self::throw_error();