예제 #1
0
 /**
  *
  *
  * @return unknown
  */
 public function download_csv()
 {
     if (!$this->orders) {
         return false;
     }
     extract(WCV_Orders::format_order_details($this->orders, $this->product_id));
     $headers = WCV_Orders::get_headers();
     // Export the CSV
     require_once wcv_plugin_dir . 'classes/front/orders/class-export-csv.php';
     WCV_Export_CSV::output_csv($this->product_id, $headers, $body, $items);
 }
예제 #2
0
 /**
  * Sort the data for CSV output first
  *
  * @param int   $product_id
  * @param array $headers
  * @param array $body
  * @param array $items
  */
 public static function output_csv($product_id, $headers, $body, $items)
 {
     $headers['quantity'] = __('Quantity', 'wcvendors');
     $new_body = array();
     foreach ($body as $i => $order) {
         // Remove comments
         unset($body[$i]['comments']);
         // Remove all numeric keys in each order (these are the meta values we are redoing into new lines)
         foreach ($order as $key => $col) {
             if (is_int($key)) {
                 unset($order[$key]);
             }
         }
         // New order row
         $new_row = $body[$i];
         // Remove order to redo
         unset($body[$i]);
         $order = new WC_Order($i);
         foreach ($items[$i]['items'] as $item) {
             $product_id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
             $new_row_with_meta = $new_row;
             // Add the qty row
             $new_row_with_meta[] = $item['qty'];
             $item_meta = $item['name'];
             if ($metadata = $order->has_meta($item['product_id'])) {
                 foreach ($metadata as $meta) {
                     // Skip hidden core fields
                     if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', WC_Vendors::$pv_options->get_option('sold_by_label'))))) {
                         continue;
                     }
                     // Skip serialised meta
                     if (is_serialized($meta['meta_value'])) {
                         continue;
                     }
                     // Get attribute data
                     if (taxonomy_exists(wc_sanitize_taxonomy_name($meta['meta_key']))) {
                         $term = get_term_by('slug', $meta['meta_value'], wc_sanitize_taxonomy_name($meta['meta_key']));
                         $meta['meta_key'] = wc_attribute_label(wc_sanitize_taxonomy_name($meta['meta_key']));
                         $meta['meta_value'] = isset($term->name) ? $term->name : $meta['meta_value'];
                     } else {
                         $meta['meta_key'] = apply_filters('woocommerce_attribute_label', wc_attribute_label($meta['meta_key'], $_product), $meta['meta_key']);
                     }
                     $item_meta .= wp_kses_post(rawurldecode($meta['meta_key'])) . ':' . wp_kses_post(wpautop(make_clickable(rawurldecode($meta['meta_value']))));
                 }
             }
             $new_row_with_meta['product'] = $item_meta;
             $new_body[] = $new_row_with_meta;
         }
     }
     $headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
     $body = apply_filters('wcvendors_csv_body', $new_body, $product_id, $items);
     WCV_Export_CSV::download($headers, $body, $product_id);
 }
예제 #3
0
 /**
  * Sort the data for CSV output first
  *
  * @param int   $product_id
  * @param array $headers
  * @param array $body
  * @param array $items
  */
 public static function output_csv($product_id, $headers, $body, $items)
 {
     $headers['quantity'] = __('Quantity', 'wcvendors');
     $new_body = array();
     foreach ($body as $i => $order) {
         // Remove comments
         unset($body[$i]['comments']);
         // Remove all numeric keys in each order (these are the meta values we are redoing into new lines)
         foreach ($order as $key => $col) {
             if (is_int($key)) {
                 unset($order[$key]);
             }
         }
         // New order row
         $new_row = $body[$i];
         // Remove order to redo
         unset($body[$i]);
         foreach ($items[$i]['items'] as $item) {
             $item_meta = new WC_Order_Item_Meta($item['item_meta']);
             $item_meta_options = $item_meta->get_formatted();
             // $item_meta = $item_meta->display( true, true );
             $new_row_with_meta = $new_row;
             if (sizeof($item_meta_options) > 0) {
                 $new_row_with_meta[] = $item['qty'];
                 foreach ($item_meta_options as $item_meta_option) {
                     if (!array_key_exists($item_meta_option['label'], $headers)) {
                         $headers[$item_meta_option['label']] = $item_meta_option['label'];
                     }
                     $new_row_with_meta[] = $item_meta_option['value'];
                 }
             } else {
                 $new_row_with_meta[] = $item['qty'];
             }
             $new_body[] = $new_row_with_meta;
         }
     }
     $headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
     $body = apply_filters('wcvendors_csv_body', $new_body, $product_id, $items);
     WCV_Export_CSV::download($headers, $body, $product_id);
 }
예제 #4
0
 /**
  * Sort the data for CSV output first
  *
  * @param int   $product_id
  * @param array $headers
  * @param array $body
  * @param array $items
  */
 public static function output_csv($product_id, $headers, $body, $items)
 {
     foreach ($body as $i => $data) {
         unset($body[$i]['comments']);
         foreach ($items[$i]['items'] as $item) {
             $item_meta = new WC_Order_Item_Meta($item['item_meta']);
             $item_meta = $item_meta->display(true, true);
             if (!empty($item_meta)) {
                 $meta = true;
                 $body[$i][] = $item['qty'] . 'x: ' . html_entity_decode($item_meta);
             } else {
                 $body[$i][] = $item['qty'];
             }
         }
     }
     if ($meta) {
         $headers['meta'] = __('Extra data', 'wcvendors');
     } else {
         $headers['quantity'] = __('Quantity', 'wcvendors');
     }
     $headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
     $body = apply_filters('wcvendors_csv_body', $body, $product_id, $items);
     WCV_Export_CSV::download($headers, $body, $product_id);
 }