Example #1
0
 /**
  * Constructor
  */
 function __construct()
 {
     if (!is_admin()) {
         return;
     }
     add_action('edit_user_profile', array($this, 'show_extra_profile_fields'));
     add_action('edit_user_profile_update', array($this, 'save_extra_profile_fields'));
     add_filter('add_menu_classes', array($this, 'show_pending_number'));
     // add_filter( 'get_terms', array( $this, 'get_terms_filter' ), 10, 3 );
     // Displaying users by the Vendor role
     if (!empty($_GET['role']) && $_GET['role'] == 'vendor') {
         add_action('manage_users_columns', array($this, 'manage_users_columns'));
         add_action('manage_users_custom_column', array($this, 'custom_manage_users_column_value'), 10, 3);
         add_filter('manage_users_sortable_columns', array($this, 'custom_sortable'));
     }
     // Disabling non-vendor related items on the admin screens
     if (PV_Vendors::is_vendor(get_current_user_id())) {
         add_filter('woocommerce_csv_product_role', array($this, 'csv_import_suite_compatibility'));
         add_filter('woocommerce_csv_product_export_args', array($this, 'csv_import_suite_compatibility_export'));
         // Admin page lockdown
         remove_action('admin_init', 'woocommerce_prevent_admin_access');
         add_action('admin_init', array($this, 'prevent_admin_access'));
         add_filter('woocommerce_prevent_admin_access', array($this, 'deny_admin_access'));
         // WC > Product page fixes
         add_action('load-edit.php', array($this, 'edit_nonvendors'));
         add_filter('views_edit-product', array($this, 'hide_nonvendor_links'));
         add_action('pre_get_posts', array($this, 'users_own_attachments'));
         add_action('admin_menu', array($this, 'remove_menu_page'), 99);
         add_action('add_meta_boxes', array($this, 'remove_meta_boxes'), 99);
         add_filter('product_type_selector', array($this, 'filter_product_types'), 99, 2);
         add_filter('product_type_options', array($this, 'filter_product_type_options'), 99);
         add_filter('woocommerce_duplicate_product_capability', array($this, 'add_duplicate_capability'));
     }
 }
Example #2
0
 /**
  *
  *
  * @param unknown $name
  * @param unknown $_product
  *
  * @return unknown
  */
 function show_vendor_in_email($name, $_product)
 {
     $product = get_post($_product->id);
     $sold_by = PV_Vendors::is_vendor($product->post_author) ? sprintf('<a href="%s" target="_TOP">%s</a>', PV_Vendors::get_vendor_shop_page($product->post_author), PV_Vendors::get_vendor_shop_name($product->post_author)) : get_bloginfo('name');
     $name .= '<small><br />' . __('Sold by', 'wc_product_vendor') . ': ' . $sold_by . '</small><br />';
     return $name;
 }
Example #3
0
 /**
  * Store all commission due for an order
  *
  * @return bool
  *
  * @param int $order_id
  */
 public function log_commission_due($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     $dues = PV_Vendors::get_vendor_dues_from_order($order, false);
     foreach ($dues as $vendor_id => $details) {
         // Only process vendor commission
         if (!PV_Vendors::is_vendor($vendor_id)) {
             continue;
         }
         // See if they currently have an amount due
         $due = PV_Vendors::count_due_by_vendor($vendor_id, $order_id);
         if ($due > 0) {
             continue;
         }
         // Get the dues in an easy format for inserting to our table
         $total_due = 0;
         $insert_due = array();
         foreach ($details as $detail) {
             $product_id = $detail['product_id'];
             $insert_due[$product_id] = array('order_id' => $order_id, 'vendor_id' => $vendor_id, 'product_id' => $product_id, 'total_due' => !empty($insert_due[$product_id]['total_due']) ? $detail['commission'] + $insert_due[$product_id]['total_due'] : $detail['commission'], 'total_shipping' => $detail['shipping'], 'tax' => $detail['tax'], 'qty' => $detail['qty'], 'time' => $order->order_date);
             $total_due += $detail['total'];
         }
         if (!empty($insert_due)) {
             PV_Vendors::update_total_due($vendor_id, $total_due);
             PV_Commission::insert_new_commission(array_values($insert_due));
         }
     }
 }
Example #4
0
 /**
  *
  *
  * @param unknown $order
  * @param unknown $group (optional)
  *
  * @return unknown
  */
 public function get_vendor_dues_from_order($order, $group = true)
 {
     global $woocommerce;
     $give_tax = Product_Vendor::$pv_options->get_option('give_tax');
     $receiver = array();
     $shipping_given = 0;
     $tax_given = 0;
     foreach ($order->get_items() as $key => $product) {
         $product_id = !empty($product['variation_id']) ? $product['variation_id'] : $product['product_id'];
         $author = PV_Vendors::get_vendor_from_product($product_id);
         $is_vendor = PV_Vendors::is_vendor($author);
         $commission = $is_vendor ? PV_Commission::calculate_commission($product['line_subtotal'], $product_id, $order) : 0;
         $tax = !empty($product['line_tax']) ? (double) $product['line_tax'] : 0;
         $shipping = PV_Shipping::get_shipping_due($order->id, $product, $author);
         if ($is_vendor) {
             $shipping_given += $shipping;
             $tax_given += $give_tax ? $tax : 0;
             $give = 0;
             $give += !empty($receiver[$author]['total']) ? $receiver[$author]['total'] : 0;
             $give += $shipping;
             $give += $commission;
             $give += $give_tax ? $tax : 0;
             if ($group) {
                 $receiver[$author] = array('vendor_id' => (int) $author, 'commission' => !empty($receiver[$author]['commission']) ? $receiver[$author]['commission'] + $commission : $commission, 'shipping' => !empty($receiver[$author]['shipping']) ? $receiver[$author]['shipping'] + $shipping : $shipping, 'tax' => $give_tax ? !empty($receiver[$author]['tax']) ? $receiver[$author]['tax'] + $tax : $tax : 0, 'qty' => !empty($receiver[$author]['qty']) ? $receiver[$author]['qty'] + $product['qty'] : $product['qty'], 'total' => $give);
             } else {
                 $receiver[$author][$product_id] = array('vendor_id' => (int) $author, 'product_id' => $product_id, 'commission' => $commission, 'shipping' => $shipping, 'tax' => $give_tax ? $tax : 0, 'qty' => $product['qty'], 'total' => $shipping + $commission + ($give_tax ? $tax : 0));
             }
         }
         $admin_comm = $product['line_subtotal'] - $commission;
         if ($group) {
             $receiver[1] = array('vendor_id' => 1, 'qty' => !empty($receiver[1]['qty']) ? $receiver[1]['qty'] + $product['qty'] : $product['qty'], 'commission' => !empty($receiver[1]['commission']) ? $receiver[1]['commission'] + $admin_comm : $admin_comm, 'total' => !empty($receiver[1]) ? $receiver[1]['total'] + $admin_comm : $admin_comm);
         } else {
             $receiver[1][$product_id] = array('vendor_id' => 1, 'product_id' => $product_id, 'commission' => $admin_comm, 'shipping' => 0, 'tax' => 0, 'qty' => $product['qty'], 'total' => $admin_comm);
         }
     }
     // Add remainders on end to admin
     $discount = $order->get_total_discount();
     $shipping = $order->order_shipping - $shipping_given;
     $tax = $order->order_tax + $order->order_shipping_tax - $tax_given;
     $total = $tax + $shipping - $discount;
     if ($group) {
         $receiver[1]['commission'] = $receiver[1]['commission'] - $discount;
         $receiver[1]['shipping'] = $shipping;
         $receiver[1]['tax'] = $tax;
         $receiver[1]['total'] += $total;
     } else {
         $receiver[1][$product_id]['commission'] = $receiver[1][$product_id]['commission'] - $discount;
         $receiver[1][$product_id]['shipping'] = $order->order_shipping - $shipping_given;
         $receiver[1][$product_id]['tax'] = $tax;
         $receiver[1][$product_id]['total'] += $total;
     }
     // Reset the array keys
     // $receivers = array_values( $receiver );
     return $receiver;
 }
Example #5
0
 /**
  *
  *
  * @param unknown $tabs
  *
  * @return unknown
  */
 public function seller_info_tab($tabs)
 {
     global $post;
     if (PV_Vendors::is_vendor($post->post_author)) {
         self::$seller_info = get_user_meta($post->post_author, 'pv_seller_info', true);
         if (!empty(self::$seller_info)) {
             $tabs['seller_info'] = array('title' => apply_filters('wc_product_vendor_seller_info_label', __('Seller info', 'wc_product_vendor')), 'priority' => 50, 'callback' => array('PV_Vendor_Shop', 'seller_info_tab_panel'));
         }
     }
     return $tabs;
 }
 /**
  * trigger function.
  *
  * @access public
  * @return void
  *
  * @param unknown $order_id
  */
 function trigger($post_id, $post)
 {
     if (!PV_Vendors::is_vendor($post->post_author)) {
         return;
     }
     $this->find[] = '{product_name}';
     $this->product_name = $post->post_title;
     $this->replace[] = $this->product_name;
     $this->find[] = '{vendor_name}';
     $this->vendor_name = PV_Vendors::get_vendor_shop_name($post->post_author);
     $this->replace[] = $this->vendor_name;
     $this->post_id = $post_id;
     $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
 }
 /**
  *
  *
  * @param unknown $order
  *
  * @return unknown
  */
 public function get_vendors($order)
 {
     $items = $order->get_items();
     foreach ($items as $key => $product) {
         if (empty($product['product_id'])) {
             continue;
         }
         $author = PV_Vendors::get_vendor_from_product($product['product_id']);
         // Only store the vendor authors
         if (!PV_Vendors::is_vendor($author)) {
             unset($items[$key]);
             continue;
         }
         $vendors[$author] = get_userdata($author)->user_email;
     }
     return $vendors;
 }
Example #8
0
 /**
  * Use views to display the Orders page
  *
  * @return html
  */
 public function display_product_orders()
 {
     if (!PV_Vendors::is_vendor(get_current_user_id())) {
         ob_start();
         woocommerce_get_template('denied.php', array(), 'wc-product-vendor/dashboard/', pv_plugin_dir . 'views/dashboard/');
         return ob_get_clean();
     }
     if (empty($_GET['orders_for_product'])) {
         return __('You haven\'t selected a product\'s orders to view! Please go back to the Vendor Dashboard and click Show Orders on the product you\'d like to view.', 'wc_product_vendor');
     }
     if (!$this->orders) {
         return __('No orders.', 'wc_product_vendor');
     }
     if (!empty($_POST['submit_comment'])) {
         require_once pv_plugin_dir . 'classes/front/orders/class-submit-comment.php';
         PV_Submit_Comment::new_comment($this->orders);
     }
     if (isset($_POST['mark_shipped'])) {
         $order_id = (int) $_POST['order_id'];
         $product_id = (int) $_POST['product_id'];
         exit;
     }
     if (isset($_POST['update_tracking'])) {
         $order_id = (int) $_POST['order_id'];
         $product_id = (int) $_POST['product_id'];
         $tracking_provider = woocommerce_clean($_POST['tracking_provider']);
         $custom_tracking_provider = woocommerce_clean($_POST['custom_tracking_provider']);
         $custom_tracking_link = woocommerce_clean($_POST['custom_tracking_link']);
         $tracking_number = woocommerce_clean($_POST['tracking_number']);
         $date_shipped = woocommerce_clean(strtotime($_POST['date_shipped']));
         $order = new WC_Order($order_id);
         $products = $order->get_items();
         foreach ($products as $key => $value) {
             if ($value['product_id'] == $product_id || $value['variation_id'] == $product_id) {
                 $order_item_id = $key;
                 break;
             }
         }
         if ($order_item_id) {
             woocommerce_delete_order_item_meta(2048, __('Tracking number', 'wc_product_vendor'));
             woocommerce_add_order_item_meta(2048, __('Tracking number', 'wc_product_vendor'), $tracking_number);
             $message = __('Success. Your tracking number has been updated.', 'wc_product_vendor');
             if (function_exists('wc_add_message')) {
                 wc_add_message($message);
             } else {
                 $woocommerce->add_message($message);
             }
             // Update order data
             update_post_meta($order_id, '_tracking_provider', $tracking_provider);
             update_post_meta($order_id, '_custom_tracking_provider', $custom_tracking_provider);
             update_post_meta($order_id, '_tracking_number', $tracking_number);
             update_post_meta($order_id, '_custom_tracking_link', $custom_tracking_link);
             update_post_meta($order_id, '_date_shipped', $date_shipped);
         }
     }
     $headers = PV_Orders::get_headers();
     $all = PV_Orders::format_order_details($this->orders, $this->product_id);
     wp_enqueue_style('pv_frontend_style', pv_assets_url . 'css/pv-frontend.css');
     wp_enqueue_script('pv_frontend_script', pv_assets_url . 'js/front-orders.js');
     // WC Shipment Tracking Providers
     global $WC_Shipment_Tracking;
     $providers = !empty($WC_Shipment_Tracking->providers) ? $WC_Shipment_Tracking->providers : false;
     $provider_array = array();
     if ($providers) {
         foreach ($providers as $providerss) {
             foreach ($providerss as $provider => $format) {
                 $provider_array[sanitize_title($provider)] = urlencode($format);
             }
         }
     }
     // End
     ob_start();
     // Show the Export CSV button
     if ($this->can_export_csv) {
         woocommerce_get_template('csv-export.php', array(), 'wc-product-vendor/orders/', pv_plugin_dir . 'views/orders/');
     }
     woocommerce_get_template('orders.php', array('headers' => $headers, 'body' => $all['body'], 'items' => $all['items'], 'product_id' => $all['product_id'], 'providers' => $providers, 'provider_array' => $provider_array), 'wc-product-vendor/orders/', pv_plugin_dir . 'views/orders/');
     return ob_get_clean();
 }
 /**
  *
  *
  * @return unknown
  */
 public function can_view_vendor_page()
 {
     if (!is_user_logged_in()) {
         return false;
     } else {
         if (!PV_Vendors::is_vendor(get_current_user_id())) {
             woocommerce_get_template('denied.php', array(), 'wc-product-vendor/dashboard/', pv_plugin_dir . 'views/dashboard/');
             return false;
         }
     }
     return true;
 }
Example #10
0
 /**
  *
  */
 public function sold_by_meta()
 {
     $author_id = get_the_author_meta('ID');
     $sold_by = PV_Vendors::is_vendor($author_id) ? sprintf('<a href="%s" target="_TOP">%s</a>', PV_Vendors::get_vendor_shop_page($author_id), PV_Vendors::get_vendor_shop_name($author_id)) : get_bloginfo('name');
     echo __('Sold by', 'wc_product_vendor') . ': ' . $sold_by . '<br/>';
 }