示例#1
0
 /**
  *
  */
 public function display_shortcodes()
 {
     if (is_page(WC_Vendors::$pv_options->get_option('orders_page')) && $this->can_view_orders) {
         wp_enqueue_script('jquery');
         $this->product_id = !empty($_GET['orders_for_product']) ? (int) $_GET['orders_for_product'] : false;
         $products = array($this->product_id);
         $_product = get_product($this->product_id);
         $children = $_product->get_children();
         if (!empty($children)) {
             $products = array_merge($products, $children);
             $products = array_unique($products);
         }
         $this->orders = WCV_Queries::get_orders_for_products($products, array('vendor_id' => get_current_user_id()));
         add_action('init', array($this, 'verify_order_access'));
         add_shortcode('wcv_orders', array($this, 'display_product_orders'));
         if ($this->can_export_csv && !empty($_POST['export_orders'])) {
             $this->download_csv();
         }
     }
 }
 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;
 }
 /**
  * [wcv_vendor_dashboard] shortcode
  *
  * @param array $atts
  *
  * @return unknown
  */
 public function display_vendor_products($atts)
 {
     global $start_date, $end_date;
     $start_date = !empty($_SESSION['PV_Session']['start_date']) ? $_SESSION['PV_Session']['start_date'] : strtotime(date('Ymd', strtotime(date('Ym', current_time('timestamp')) . '01')));
     $end_date = !empty($_SESSION['PV_Session']['end_date']) ? $_SESSION['PV_Session']['end_date'] : strtotime(date('Ymd', current_time('timestamp')));
     $can_view_orders = WC_Vendors::$pv_options->get_option('can_show_orders');
     $settings_page = get_permalink(WC_Vendors::$pv_options->get_option('shop_settings_page'));
     $can_submit = WC_Vendors::$pv_options->get_option('can_submit_products');
     $submit_link = $can_submit ? admin_url('post-new.php?post_type=product') : '';
     $edit_link = $can_submit ? admin_url('edit.php?post_type=product') : '';
     if (!$this->can_view_vendor_page()) {
         return false;
     }
     extract(shortcode_atts(array('user_id' => get_current_user_id(), 'datepicker' => true), $atts));
     $vendor_products = WCV_Queries::get_commission_products($user_id);
     $products = array();
     foreach ($vendor_products as $_product) {
         $products[] = $_product->ID;
     }
     $vendor_summary = $this->format_product_details($vendor_products);
     $order_summary = WCV_Queries::get_orders_for_products($products);
     $shop_page = WCV_Vendors::get_vendor_shop_page(wp_get_current_user()->user_login);
     wp_enqueue_style('wcv_frontend_style', wcv_assets_url . 'css/wcv-frontend.css');
     $providers = array();
     $provider_array = array();
     // WC Shipment Tracking Providers
     if (class_exists('WC_Shipment_Tracking')) {
         $WC_Shipment_Tracking = new WC_Shipment_Tracking();
         $providers = method_exists($WC_Shipment_Tracking, 'get_providers') ? $WC_Shipment_Tracking->get_providers() : $WC_Shipment_Tracking->providers;
         $provider_array = array();
         foreach ($providers as $all_providers) {
             foreach ($all_providers as $provider => $format) {
                 $provider_array[sanitize_title($provider)] = urlencode($format);
             }
         }
     }
     ob_start();
     do_action('wcvendors_before_dashboard');
     wc_print_notices();
     wc_get_template('links.php', array('shop_page' => urldecode($shop_page), 'settings_page' => $settings_page, 'can_submit' => $can_submit, 'submit_link' => $submit_link, 'edit_link' => $edit_link), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/');
     if ($can_view_sales = WC_Vendors::$pv_options->get_option('can_view_frontend_reports')) {
         wc_get_template('reports.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'vendor_summary' => $vendor_summary, 'datepicker' => $datepicker, 'can_view_orders' => $can_view_orders), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/');
     }
     wc_get_template('orders.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'order_summary' => $order_summary, 'datepicker' => $datepicker, 'providers' => $providers, 'provider_array' => $provider_array, 'can_view_orders' => $can_view_orders), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/');
     do_action('wcvendors_after_dashboard');
     if (function_exists('wc_enqueue_js')) {
         wc_enqueue_js(WCV_Vendor_dashboard::wc_st_js($provider_array));
     } else {
         $woocommerce->add_inline_js($js);
     }
     return ob_get_clean();
 }
 /**
  * [pv_recent_vendor_sales] shortcode
  *
  * @param array $atts
  *
  * @return unknown
  */
 public function display_vendor_products($atts)
 {
     global $start_date, $end_date;
     $start_date = !empty($_SESSION['PV_Session']['start_date']) ? $_SESSION['PV_Session']['start_date'] : strtotime(date('Ymd', strtotime(date('Ym', current_time('timestamp')) . '01')));
     $end_date = !empty($_SESSION['PV_Session']['end_date']) ? $_SESSION['PV_Session']['end_date'] : strtotime(date('Ymd', current_time('timestamp')));
     $can_view_orders = WC_Vendors::$pv_options->get_option('can_show_orders');
     $settings_page = get_permalink(WC_Vendors::$pv_options->get_option('shop_settings_page'));
     $can_submit = WC_Vendors::$pv_options->get_option('can_submit_products');
     if ($can_submit) {
         $submit_link = admin_url('post-new.php?post_type=product');
     }
     if (!$this->can_view_vendor_page()) {
         return false;
     }
     extract(shortcode_atts(array('user_id' => get_current_user_id(), 'datepicker' => true), $atts));
     $vendor_products = WCV_Queries::get_commission_products($user_id);
     $products = array();
     foreach ($vendor_products as $_product) {
         $products[] = $_product->ID;
     }
     $vendor_summary = $this->format_product_details($vendor_products);
     $order_summary = WCV_Queries::get_orders_for_products($products);
     $shop_page = WCV_Vendors::get_vendor_shop_page(wp_get_current_user()->user_login);
     wp_enqueue_style('pv_frontend_style', wcv_assets_url . 'css/pv-frontend.css');
     ob_start();
     do_action('wcvendors_before_dashboard');
     wc_print_notices();
     woocommerce_get_template('links.php', array('shop_page' => urldecode($shop_page), 'settings_page' => $settings_page, 'can_submit' => $can_submit, 'submit_link' => $submit_link), 'wc-product-vendor/dashboard/', wcv_plugin_dir . 'views/dashboard/');
     woocommerce_get_template('reports.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'vendor_summary' => $vendor_summary, 'datepicker' => $datepicker, 'can_view_orders' => $can_view_orders), 'wc-product-vendor/dashboard/', wcv_plugin_dir . 'views/dashboard/');
     woocommerce_get_template('orders.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'order_summary' => $order_summary, 'datepicker' => $datepicker, 'can_view_orders' => $can_view_orders), 'wc-product-vendor/dashboard/', wcv_plugin_dir . 'views/dashboard/');
     do_action('wcvendors_after_dashboard');
     return ob_get_clean();
 }