Exemplo n.º 1
0
 /**
  * Sum of orders for a specific order
  *
  * @param array $order_ids
  * @param array $args (optional)
  *
  * @return object
  */
 public static function sum_for_orders(array $order_ids, array $args = array())
 {
     global $wpdb;
     $dates = WCV_Queries::orders_within_range();
     $defaults = array('status' => apply_filters('wcvendors_completed_statuses', array('completed', 'processing')), 'dates' => array('before' => $dates['before'], 'after' => $dates['after']));
     $args = wp_parse_args($args, $defaults);
     $sql = "\n\t\t\tSELECT COUNT(order_id) as total_orders,\n\t\t\t       SUM(total_due + total_shipping + tax) as line_total,\n\t\t\t       SUM(qty) as qty,\n\t\t\t       product_id\n\n\t\t\tFROM {$wpdb->prefix}pv_commission\n\n\t\t\tWHERE   order_id IN ('" . implode("','", $order_ids) . "')\n\t\t";
     if (!empty($args['dates']['after'])) {
         $sql .= "\n\t\t\t\tAND     time >= '" . $args['dates']['after'] . "'\n\t\t\t";
     }
     if (!empty($args['dates']['before'])) {
         $sql .= "\n\t\t\t\tAND     time <= '" . $args['dates']['before'] . "'\n\t\t\t";
     }
     $sql .= "\n\t\t\tAND     status != 'reversed'\n\t\t";
     if (!empty($args['vendor_id'])) {
         $sql .= "\n\t\t\t\tAND vendor_id = {$args['vendor_id']}\n\t\t\t";
     }
     $sql .= "\n\t\t\tGROUP BY order_id\n\t\t\tORDER BY time DESC;\n\t\t";
     $orders = $wpdb->get_results($sql);
     return $orders;
 }