Handles the edit posts views and some functionality on the edit post screen for WC post types.
 public function get_wooc_product_data()
 {
     global $post, $the_product;
     $user_data = $this->user_data;
     $user_email = $user_data->email;
     $user_ID = $user_data->user_id;
     $orders_data = array();
     $order_products = array();
     include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/class-wc-admin-post-types.php';
     $CPT_Product = new WC_Admin_Post_Types();
     $args = array('numberposts' => -1, 'post_type' => 'product', 'post_status' => 'publish');
     #$products = get_posts( $args );
     $products = wcrm_customer_bought_products($user_email, $user_ID);
     foreach ($products as $prod) {
         $post = get_post($prod->ID);
         $the_product = wc_get_product($prod->ID);
         if (!wc_customer_bought_product($user_email, $user_ID, $prod->ID)) {
             # continue;
         }
         $o['ID'] = $prod->ID;
         ob_start();
         $CPT_Product->render_product_columns('thumb');
         $o['thumb'] = ob_get_contents();
         ob_end_clean();
         ob_start();
         $edit_link = get_edit_post_link($prod->ID);
         $title = _draft_or_post_title();
         echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>';
         $o['name'] = ob_get_contents();
         ob_end_clean();
         ob_start();
         $CPT_Product->render_product_columns('sku');
         $o['sku'] = ob_get_contents();
         ob_end_clean();
         $o['number_purchased'] = $prod->items_count;
         $o['value_purchases'] = wc_price($prod->line_total);
         $orders_data[] = $o;
     }
     return $orders_data;
 }
 function get_wooc_product_data()
 {
     global $post, $woocommerce, $the_order;
     $orders_data = array();
     $order_products = array();
     if (defined('WC_VERSION') && floatval(WC_VERSION) >= 2.2) {
         include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/class-wc-admin-post-types.php';
         $CPT_Product = new WC_Admin_Post_Types();
         $args = array('numberposts' => -1, 'post_type' => 'product', 'post_status' => 'publish');
         $products = get_posts($args);
         foreach ($products as $post) {
             #$post = get_post($prod_id);
             $o['ID'] = $post->ID;
             ob_start();
             $CPT_Product->render_product_columns('thumb');
             $o['thumb'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $edit_link = get_edit_post_link($post->ID);
             $title = _draft_or_post_title();
             echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>';
             $o['name'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->render_product_columns('sku');
             $o['sku'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->render_product_columns('is_in_stock');
             $o['is_in_stock'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->render_product_columns('price');
             $o['price'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->render_product_columns('product_cat');
             $o['product_cat'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->render_product_columns('product_type');
             $o['product_type'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             if ('0000-00-00 00:00:00' == $post->post_date) {
                 $t_time = $h_time = __('Unpublished', 'woocommerce');
             } else {
                 $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
                 $gmt_time = strtotime($post->post_date_gmt . ' UTC');
                 $time_diff = current_time('timestamp', 1) - $gmt_time;
                 if ($time_diff > 0 && $time_diff < 24 * 60 * 60) {
                     $h_time = sprintf(__('%s ago', 'woocommerce'), human_time_diff($gmt_time, current_time('timestamp', 1)));
                 } else {
                     $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post);
                 }
             }
             echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>';
             $o['date'] = ob_get_contents();
             ob_end_clean();
             $orders_data[] = $o;
         }
     } else {
         $args = array('numberposts' => -1, 'post_type' => 'product', 'post_status' => 'publish');
         $args = $this->product_filters_query($args);
         $orders = get_posts($args);
         $CPT_Product = new WC_Admin_CPT_Product();
         $user_email = '';
         if (isset($_GET['order_id'])) {
             $user_order_id = $_GET['order_id'];
             $u = new WC_Order($user_order_id);
             $user_email = $u->billing_email;
             /**/
             $args_ = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => 'publish');
             $orders_ = get_posts($args_);
             foreach ($orders_ as $order_) {
                 $id = $order_->ID;
                 if (!empty($user_email)) {
                     $t = new WC_Order($id);
                     if ($user_email != $t->billing_email) {
                         continue;
                     }
                 }
                 $order_d = new WC_Order($order_->ID);
                 $items = $order_d->get_items();
                 foreach ($items as $item) {
                     $prod_id = $item['item_meta']['_product_id'][0];
                     if (!in_array($prod_id, $order_products)) {
                         $order_products[] = $prod_id;
                     }
                 }
             }
             /**/
         }
         foreach ($orders as $order) {
             $post = $order;
             if (!in_array($post->ID, $order_products)) {
                 continue;
             }
             $o['ID'] = $post->ID;
             ob_start();
             $CPT_Product->custom_columns('thumb');
             $o['thumb'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $edit_link = get_edit_post_link($post->ID);
             $title = _draft_or_post_title();
             echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>';
             $o['name'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->custom_columns('sku');
             $o['sku'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->custom_columns('is_in_stock');
             $o['is_in_stock'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->custom_columns('price');
             $o['price'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->custom_columns('product_cat');
             $o['product_cat'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Product->custom_columns('product_type');
             $o['product_type'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             if ('0000-00-00 00:00:00' == $post->post_date) {
                 $t_time = $h_time = __('Unpublished', 'woocommerce');
             } else {
                 $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
                 $gmt_time = strtotime($post->post_date_gmt . ' UTC');
                 $time_diff = current_time('timestamp', 1) - $gmt_time;
                 if ($time_diff > 0 && $time_diff < 24 * 60 * 60) {
                     $h_time = sprintf(__('%s ago', 'woocommerce'), human_time_diff($gmt_time, current_time('timestamp', 1)));
                 } else {
                     $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post);
                 }
             }
             echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>';
             $o['date'] = ob_get_contents();
             ob_end_clean();
             $orders_data[] = $o;
         }
     }
     return $orders_data;
 }
示例#3
-1
 function get_wooc_orders_data()
 {
     global $post, $woocommerce, $the_order;
     if (defined('WC_VERSION') && floatval(WC_VERSION) >= 2.2) {
         $orders_data = array();
         include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/class-wc-admin-post-types.php';
         $CPT_Shop_Order = new WC_Admin_Post_Types();
         $user_email = '';
         if (isset($_GET['order_id'])) {
             $user_order_id = $_GET['order_id'];
             $u = new WC_Order($user_order_id);
             $user_email = $u->billing_email;
             if (empty($user_email)) {
                 return $orders_data;
             }
             $args = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => array_keys(wc_get_order_statuses()), 'meta_query' => array(array('key' => '_billing_email', 'value' => $user_email)));
         } else {
             if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
                 $identifier = get_option('woocommerce_crm_unique_identifier');
                 if ($identifier == 'username_email') {
                     $args = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => array_keys(wc_get_order_statuses()), 'meta_query' => array(array('key' => '_customer_user', 'value' => $_GET['user_id'])));
                 } else {
                     $user_email = get_user_meta($_GET['user_id'], 'billing_email', true);
                     if (empty($user_email)) {
                         return $orders_data;
                     }
                     $args = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => array_keys(wc_get_order_statuses()), 'meta_query' => array(array('key' => '_billing_email', 'value' => $user_email)));
                 }
             }
         }
         $orders = get_posts($args);
         foreach ($orders as $order) {
             $id = $order->ID;
             $post = $order;
             $o['ID'] = $post->ID;
             $post_status = get_post_status($post->ID);
             $st = array('wc-pending', 'wc-failed', 'wc-on-hold', 'wc-processing', 'wc-completed', 'wc-refunded', 'wc-cancelled');
             if (!in_array($post_status, $st)) {
                 ob_start();
                 do_action('manage_shop_order_posts_custom_column', 'order_status');
                 $o['order_status'] = ob_get_contents();
                 ob_end_clean();
             } else {
                 ob_start();
                 $CPT_Shop_Order->render_shop_order_columns('order_status');
                 $o['order_status'] = ob_get_contents();
                 ob_end_clean();
             }
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('order_title');
             $o['order_title'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('order_items');
             $o['order_items'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('shipping_address');
             $o['shipping_address'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('customer_message');
             $o['customer_message'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
             if (defined('WC_VERSION') && floatval(WC_VERSION) >= 2.2) {
                 remove_filter('comments_clauses', array('WC_Comments', 'exclude_webhook_comments'), 10, 1);
             }
             $CPT_Shop_Order->render_shop_order_columns('order_notes');
             add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
             if (defined('WC_VERSION') && floatval(WC_VERSION) >= 2.2) {
                 add_filter('comments_clauses', array('WC_Comments', 'exclude_webhook_comments'), 10, 1);
             }
             $o['order_notes'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('order_date');
             $o['order_date'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->render_shop_order_columns('order_total');
             $o['order_total'] = ob_get_contents();
             ob_end_clean();
             $orders_data[] = $o;
         }
     } else {
         $orders_data = array();
         $CPT_Shop_Order = new WC_Admin_CPT_Shop_Order();
         $user_email = '';
         if (isset($_GET['order_id'])) {
             $user_order_id = $_GET['order_id'];
             $u = new WC_Order($user_order_id);
             $user_email = $u->billing_email;
         } else {
             if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
                 $user_email = get_user_meta($_GET['user_id'], 'email', true);
                 if (empty($user_email)) {
                     $user_email = get_user_meta($_GET['user_id'], 'billing_email', true);
                 }
             }
         }
         if (empty($user_email)) {
             return $orders_data;
         }
         $args = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => 'publish', 'meta_query' => array(array('key' => '_billing_email', 'value' => $user_email)));
         $orders = get_posts($args);
         foreach ($orders as $order) {
             $id = $order->ID;
             $post = $order;
             $o['ID'] = $post->ID;
             ob_start();
             $CPT_Shop_Order->custom_columns('order_status');
             $o['order_status'] = ob_get_contents();
             ob_end_clean();
             $st = array('pending', 'failed', 'on-hold', 'processing', 'completed', 'refunded', 'cancelled');
             if (!in_array(strip_tags($o['order_status']), $st)) {
                 ob_start();
                 do_action('manage_shop_order_posts_custom_column', 'order_status');
                 $o['order_status'] = ob_get_contents();
                 ob_end_clean();
             }
             ob_start();
             $CPT_Shop_Order->custom_columns('order_title');
             $o['order_title'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('order_items');
             $o['order_items'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('shipping_address');
             $o['shipping_address'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('customer_message');
             $o['customer_message'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('order_notes');
             $o['order_notes'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('order_date');
             $o['order_date'] = ob_get_contents();
             ob_end_clean();
             ob_start();
             $CPT_Shop_Order->custom_columns('order_total');
             $o['order_total'] = ob_get_contents();
             ob_end_clean();
             $orders_data[] = $o;
         }
     }
     return $orders_data;
 }