/** * Get Orders to display in admin * * @return $orders */ function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = $this->get_vendor_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = $this->get_orders_for_vendor_products($products); $model_id = 0; if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } } $products = ''; foreach ($valid as $key => $item) { $item_meta = new WC_Order_Item_Meta($item['item_meta']); // $item_meta = $item_meta->display( false, true ); $item_meta = $item_meta->get_formatted(); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; foreach ($item_meta as $key => $meta) { // Remove the sold by meta key for display if (strtolower($key) != 'sold by') { $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />'; } } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $comment_output = ''; // Need to fix how form is submitted for adding comments if at all possible. if ($this->can_view_comments) { $order_notes = $order->get_customer_order_notes(); $comment_output .= '<a href="#TB_inline?width=600&height=550&inlineId=order-comment-window-' . $model_id . '" class="thickbox">'; $comment_output .= sprintf(__('Comments (%s)', 'wcvendors'), count($order_notes)); $comment_output .= '</a>'; $comment_output .= '<div id="order-comment-window-' . $model_id . '" style="display:none;">'; $comment_output .= '<h3>' . __('Comments to Customer', 'wcvendors') . '</h3>'; if (!empty($order_notes)) { foreach ($order_notes as $order_note) { $last_added = human_time_diff(strtotime($order_note->comment_date_gmt), current_time('timestamp', 1)); $comment_output .= '<p>'; $comment_output .= $order_note->comment_content; $comment_output .= '<br />'; $comment_output .= sprintf(__('added %s ago', 'wcvendors'), $last_added); $comment_output .= '<br />'; $comment_output .= '</p>'; } } else { $comment_output .= '<p>' . __('No comments currently to customer.', 'wcvendors') . '</p>'; } if ($this->can_add_comments) { $comment_output .= wp_nonce_field('add-comment'); $comment_output .= ' <textarea name="comment_text" style="width:97%"></textarea> <input type="hidden" name="order_id" value="' . $order->id . '"> <input type="hidden" name="action" value="add_comment"> <input class="btn btn-large btn-block" type="submit" name="submit_comment" value="' . __('Add comment', 'wcvendors') . '">'; } $comment_output .= '</div>'; } $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); // $order_items[ 'comments' ] = $comment_output; $order_items['status'] = $shipped; $orders[] = (object) $order_items; $model_id++; } } return $orders; }
function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = WCV_Queries::get_commission_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = WCV_Queries::get_orders_for_products($products); if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } } $products = ''; foreach ($valid as $key => $item) { $item_meta = new WC_Order_Item_Meta($item['item_meta']); // $item_meta = $item_meta->display( false, true ); $item_meta = $item_meta->get_formatted(); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; foreach ($item_meta as $key => $meta) { // Remove the sold by meta key for display if (strtolower($key) != 'sold by') { $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />'; } } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); $order_items['status'] = $shipped; $orders[] = (object) $order_items; } } return $orders; }
_e('Links', 'wcvendors'); ?> </th> </thead> <tbody> <?php if (!empty($order_summary)) { $totals = 0; $user_id = get_current_user_id(); ?> <?php foreach ($order_summary as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $needs_shipping = false; $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } // See if product needs shipping $product = new WC_Product($value['product_id']); $needs_shipping = !$product->needs_shipping() || $product->is_downloadable('yes') ? false : true; } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers); ?>
/** * Get Orders to display in admin * * @return $orders */ function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = $this->get_vendor_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = $this->get_orders_for_vendor_products($products); $model_id = 0; if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $item) { if (in_array($item['variation_id'], $valid_items) || in_array($item['product_id'], $valid_items)) { $valid[] = $item; } } $products = ''; foreach ($valid as $key => $item) { $wc_product = new WC_Product($item['product_id']); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; if ($metadata = $order->has_meta($item['product_id'])) { $products .= '<table cellspacing="0" class="wcv_display_meta">'; 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'], $wc_product), $meta['meta_key']); } $products .= '<tr><th>' . wp_kses_post(rawurldecode($meta['meta_key'])) . ':</th><td>' . wp_kses_post(wpautop(make_clickable(rawurldecode($meta['meta_value'])))) . '</td></tr>'; } $products .= '</table>'; } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $comment_output = ''; // Need to fix how form is submitted for adding comments if at all possible. // if ( $this->can_view_comments) { // $order_notes = $order->get_customer_order_notes(); // $comment_output .= '<a href="#TB_inline?width=600&height=550&inlineId=order-comment-window-'.$model_id.'" class="thickbox">'; // $comment_output .= sprintf( __( 'Comments (%s)', 'wcvendors' ), count( $order_notes ) ); // $comment_output .= '</a>'; // $comment_output .= '<div id="order-comment-window-'.$model_id.'" style="display:none;">'; // $comment_output .= '<h3>'.__('Comments to Customer', 'wcvendors' ). '</h3>'; // if ( !empty( $order_notes ) ) { // foreach ($order_notes as $order_note) { // $last_added = human_time_diff( strtotime( $order_note->comment_date_gmt ), current_time( 'timestamp', 1 ) ); // $comment_output .= '<p>'; // $comment_output .= $order_note->comment_content; // $comment_output .= '<br />'; // $comment_output .= sprintf(__( 'added %s ago', 'wcvendors' ), $last_added ); // $comment_output .= '<br />'; // $comment_output .= '</p>'; // } // } else { // $comment_output .= '<p>'.__('No comments currently to customer.', 'wcvendors' ). '</p>'; // } // if ( $this->can_add_comments ) { // $comment_output .= wp_nonce_field( 'add-comment' ); // $comment_output .= ' // <textarea name="comment_text" style="width:97%"></textarea> // <input type="hidden" name="order_id" value="'. $order->id .'"> // <input type="hidden" name="action" value="add_comment"> // <input class="btn btn-large btn-block" type="submit" name="submit_comment" value="'.__( 'Add comment', 'wcvendors' ).'">'; // } // $comment_output .= '</div>'; // } $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); // $order_items[ 'comments' ] = $comment_output; $order_items['status'] = $shipped; $orders[] = (object) $order_items; $model_id++; } } return $orders; }