/**
  * 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'));
     // Disabling non-vendor related items on the admin screens
     if (WCV_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-post-new.php', array($this, 'confirm_access_to_add'));
         add_action('load-edit.php', array($this, 'edit_nonvendors'));
         add_filter('views_edit-product', array($this, 'hide_nonvendor_links'));
         // Filter user attachments so they only see their own attachements
         add_action('ajax_query_attachments_args', array($this, 'show_user_attachment_ajax'));
         add_filter('parse_query', array($this, 'show_user_attachment_page'));
         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'));
         // WC > Product featured
         $product_misc = (array) WC_Vendors::$pv_options->get_option('hide_product_misc');
         if (isset($product_misc['featured'])) {
             add_filter('manage_product_posts_columns', array($this, 'manage_product_columns'), 99);
         }
     }
 }
 /**
  * Store all commission due for an order
  *
  * @return bool
  *
  * @param int $order_id
  */
 public static function log_commission_due($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     $dues = WCV_Vendors::get_vendor_dues_from_order($order, false);
     foreach ($dues as $vendor_id => $details) {
         // Only process vendor commission
         if (!WCV_Vendors::is_vendor($vendor_id)) {
             continue;
         }
         // See if they currently have an amount due
         $due = WCV_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
         $insert_due = array();
         foreach ($details as $key => $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' => !empty($insert_due[$product_id]['total_shipping']) ? $detail['shipping'] + $insert_due[$product_id]['total_shipping'] : $detail['shipping'], 'tax' => !empty($insert_due[$product_id]['tax']) ? $detail['tax'] + $insert_due[$product_id]['tax'] : $detail['tax'], 'qty' => !empty($insert_due[$product_id]['qty']) ? $detail['qty'] + $insert_due[$product_id]['qty'] : $detail['qty'], 'time' => $order->order_date);
         }
         if (!empty($insert_due)) {
             WCV_Commission::insert_new_commission(array_values($insert_due));
         }
     }
 }
Example #3
0
 /**
  *
  *
  * @param unknown $name
  * @param unknown $_product
  *
  * @return unknown
  */
 function show_vendor_in_email($name, $_product)
 {
     $product = get_post($_product->id);
     $sold_by = WCV_Vendors::is_vendor($product->post_author) ? sprintf('<a href="%s">%s</a>', WCV_Vendors::get_vendor_shop_page($product->post_author), WCV_Vendors::get_vendor_sold_by($product->post_author)) : get_bloginfo('name');
     $name .= '<small class="wcvendors_sold_by_in_email"><br />' . apply_filters('wcvendors_sold_by_in_email', __('Sold by: ', 'wcvendors')) . $sold_by . '</small><br />';
     return $name;
 }
 /**
  * Single product meta 
  */
 public static function sold_by_meta()
 {
     $vendor_id = get_the_author_meta('ID');
     $sold_by_label = WC_Vendors::$pv_options->get_option('sold_by_label');
     $sold_by = WCV_Vendors::is_vendor($vendor_id) ? sprintf('<a href="%s" class="wcvendors_cart_sold_by_meta">%s</a>', WCV_Vendors::get_vendor_shop_page($vendor_id), WCV_Vendors::get_vendor_sold_by($vendor_id)) : get_bloginfo('name');
     echo apply_filters('wcvendors_cart_sold_by_meta', $sold_by_label) . $sold_by . '<br/>';
 }
 /**
  * trigger function.
  *
  * @access public
  * @return void
  *
  * @param unknown $order_id
  */
 function trigger($post_id, $post)
 {
     if (!WCV_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 = WCV_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());
 }
Example #6
0
 /**
  * Use views to display the Orders page
  *
  * @return html
  */
 public function display_product_orders()
 {
     if (!WCV_Vendors::is_vendor(get_current_user_id())) {
         ob_start();
         wc_get_template('denied.php', array(), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/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.', 'wcvendors');
     }
     if (!$this->orders) {
         return __('No orders.', 'wcvendors');
     }
     if (!empty($_POST['submit_comment'])) {
         require_once wcv_plugin_dir . 'classes/front/orders/class-submit-comment.php';
         WCV_Submit_Comment::new_comment($this->orders);
     }
     if (isset($_POST['mark_shipped'])) {
         $order_id = (int) $_POST['order_id'];
         $product_id = (int) $_POST['product_id'];
         exit;
     }
     $headers = WCV_Orders::get_headers();
     $all = WCV_Orders::format_order_details($this->orders, $this->product_id);
     wp_enqueue_style('pv_frontend_style', wcv_assets_url . 'css/wcv-frontend.css');
     wp_enqueue_script('pv_frontend_script', wcv_assets_url . 'js/front-orders.js');
     $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();
     // Show the Export CSV button
     if ($this->can_export_csv) {
         wc_get_template('csv-export.php', array(), 'wc-vendors/orders/', wcv_plugin_dir . 'templates/orders/');
     }
     wc_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-vendors/orders/', wcv_plugin_dir . 'templates/orders/');
     return ob_get_clean();
 }
 /**
  * trigger function.
  *
  * @access public
  * @return void
  *
  * @param unknown $order_id
  */
 function trigger($new_status, $old_status, $post)
 {
     // Ensure this is only firing on products
     if (!in_array($post->post_type, array('product', 'product_variation'))) {
         return;
     }
     // Ensure that the post author is a vendor
     if (!WCV_Vendors::is_vendor($post->post_author)) {
         return;
     }
     if (!$this->is_enabled()) {
         return;
     }
     $this->find[] = '{product_name}';
     $this->product_name = $post->post_title;
     $this->replace[] = $this->product_name;
     $this->find[] = '{vendor_name}';
     $this->vendor_name = WCV_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());
 }
Example #8
0
 /**
  * Use views to display the Orders page
  *
  * @return html
  */
 public function display_product_orders()
 {
     if (!WCV_Vendors::is_vendor(get_current_user_id())) {
         ob_start();
         wc_get_template('denied.php', array(), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/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.', 'wcvendors');
     }
     if (!$this->orders) {
         return __('No orders.', 'wcvendors');
     }
     if (!empty($_POST['submit_comment'])) {
         require_once wcv_plugin_dir . 'classes/front/orders/class-submit-comment.php';
         WCV_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($order_item_id, __('Tracking number', 'wcvendors'));
             woocommerce_add_order_item_meta($order_item_id, __('Tracking number', 'wcvendors'), $tracking_number);
             $message = __('Success. Your tracking number has been updated.', 'wcvendors');
             wc_add_notice($message, 'success');
             // 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 = WCV_Orders::get_headers();
     $all = WCV_Orders::format_order_details($this->orders, $this->product_id);
     wp_enqueue_style('pv_frontend_style', wcv_assets_url . 'css/wcv-frontend.css');
     wp_enqueue_script('pv_frontend_script', wcv_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) {
         wc_get_template('csv-export.php', array(), 'wc-vendors/orders/', wcv_plugin_dir . 'templates/orders/');
     }
     wc_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-vendors/orders/', wcv_plugin_dir . 'templates/orders/');
     return ob_get_clean();
 }
 /**
  *
  *
  * @return unknown
  */
 public static function can_view_vendor_page()
 {
     if (!is_user_logged_in()) {
         return false;
     } else {
         if (!WCV_Vendors::is_vendor(get_current_user_id())) {
             wc_get_template('denied.php', array(), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/');
             return false;
         }
     }
     return true;
 }
function tokopress_wcvendors_user_vendorshop()
{
    $user = get_query_var('author_name') ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
    if (WCV_Vendors::is_vendor($user->ID)) {
        $shop_name = WCV_Vendors::get_vendor_shop_name($user->ID);
        $shop_page = WCV_Vendors::get_vendor_shop_page($user->user_login);
        if ($shop_name && $shop_page) {
            echo '<div class="user-vendorshop">';
            echo '<p>' . sprintf(__('%s is a seller on &quot;%s&quot; shop.', 'tokopress'), '<strong>' . $user->display_name . '</strong>', $shop_name) . '</p>';
            echo '<a href="' . $shop_page . '" class="button alt">' . sprintf(__('Visit &quot;%s&quot;', 'tokopress'), $shop_name) . '</a>';
            echo '</div>';
        }
    }
}
 public static function add_vendor_to_order_item_meta($item_id, $cart_item)
 {
     $vendor_id = $cart_item['data']->post->post_author;
     $sold_by_label = WC_Vendors::$pv_options->get_option('sold_by_label');
     $sold_by = WCV_Vendors::is_vendor($vendor_id) ? sprintf(WCV_Vendors::get_vendor_sold_by($vendor_id)) : get_bloginfo('name');
     wc_add_order_item_meta($item_id, apply_filters('wcvendors_sold_by_in_email', $sold_by_label), $sold_by);
 }
Example #12
0
 /**
  * Split order into vendor orders (when applicable) after checkout
  *
  * @since 
  * @param int $order_id
  * @return void
  */
 public static function create_child_orders($order_id)
 {
     $order = wc_get_order($order_id);
     $items = $order->get_items();
     $vendor_items = array();
     foreach ($items as $item_id => $item) {
         if (isset($item['product_id']) && $item['product_id'] !== 0) {
             // check if product is from vendor
             $product_author = get_post_field('post_author', $item['product_id']);
             if (WCV_Vendors::is_vendor($product_author)) {
                 $vendor_items[$product_author][$item_id] = array('item_id' => $item_id, 'qty' => $item['qty'], 'total' => $item['line_total'], 'subtotal' => $item['line_subtotal'], 'tax' => $item['line_tax'], 'subtotal_tax' => $item['line_subtotal_tax'], 'tax_data' => maybe_unserialize($item['line_tax_data']), 'commission' => WCV_Commission::calculate_commission($item['line_subtotal'], $item['product_id'], $order, $item['qty']));
             }
         }
     }
     foreach ($vendor_items as $vendor_id => $items) {
         if (!empty($items)) {
             $vendor_order = WCV_Vendors::create_vendor_order(array('order_id' => $order_id, 'vendor_id' => $vendor_id, 'line_items' => $items));
         }
     }
 }
Example #13
0
 /**
  *
  */
 public static function sold_by_meta()
 {
     $author_id = get_the_author_meta('ID');
     $sold_by = WCV_Vendors::is_vendor($author_id) ? sprintf('<a href="%s">%s</a>', WCV_Vendors::get_vendor_shop_page($author_id), WCV_Vendors::get_vendor_shop_name($author_id)) : get_bloginfo('name');
     echo apply_filters('wcvendors_cart_sold_by_meta', __('Sold by: ', 'wcvendors')) . $sold_by . '<br/>';
 }
Example #14
0
    function mango_more_seller_product()
    {
        global $product, $woocommerce_loop;
        if (empty($product) || !$product->exists()) {
            return;
        }
        global $post;
        if (!WCV_Vendors::is_vendor($post->post_author)) {
            return;
        }
        $meta_query = WC()->query->get_meta_query();
        $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => 10, 'author' => get_the_author_meta('ID'), 'meta_query' => $meta_query, 'orderby' => 'rand');
        $products = new WP_Query($args);
        if ($products->have_posts()) {
            ?>
	<div class="container">
		<h2 class="vendor-moreseller"><?php 
            _e('More from this seller&hellip;', 'mango');
            ?>
</h2>
		<?php 
            woocommerce_product_loop_start();
            ?>
        <div class="owl-carousel product-featured-carousel">
			<?php 
            while ($products->have_posts()) {
                $products->the_post();
                ?>
					<?php 
                wc_get_template_part('content-product');
                ?>
			<?php 
            }
            // end of the loop.
            ?>
		</div>
		<?php 
            woocommerce_product_loop_end();
            ?>
	</div>
<?php 
        }
        wp_reset_postdata();
    }
Example #15
0
 /**
  *	 Add the vendor email to the low stock emails.  
  *
  */
 public function vendor_stock_email($emails, $product)
 {
     if (WCV_Vendors::is_vendor($product->post->post_author)) {
         $vendor_data = get_userdata($product->post->post_author);
         $vendor_email = $vendor_data->user_email;
         $emails .= ',' . $vendor_email;
     }
     return $emails;
 }
    /**
     * Show the PayPal field and commision due table
     *
     * @param unknown $user
     */
    public function show_extra_profile_fields($user)
    {
        if (!WCV_Vendors::is_vendor($user->ID) && !WCV_Vendors::is_pending($user->ID)) {
            return;
        }
        ?>
		<h3><?php 
        _e('WC Vendors', 'wcvendors');
        ?>
</h3>
		<table class="form-table">
			<tbody>
			<?php 
        do_action('wcvendors_admin_before_shop_html', $user);
        ?>
			<tr>
				<th scope="row">Shop HTML</th>
				<td>
					<label for="pv_shop_html_enabled">
						<input name="pv_shop_html_enabled" type="checkbox"
							   id="pv_shop_html_enabled" <?php 
        checked(true, get_user_meta($user->ID, 'pv_shop_html_enabled', true), $echo = true);
        ?>
/>
						<?php 
        _e('Enable HTML for the shop description', 'wcvendors');
        ?>
					</label>
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_shop_html', $user);
        ?>
			<tr>
				<th><label for="pv_shop_name"><?php 
        _e('Shop name', 'wcvendors');
        ?>
</label></th>
				<td><input type="text" name="pv_shop_name" id="pv_shop_name"
						   value="<?php 
        echo get_user_meta($user->ID, 'pv_shop_name', true);
        ?>
" class="regular-text">
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_shop_name', $user);
        ?>
			<tr>
				<th><label for="pv_paypal"><?php 
        _e('PayPal E-mail', 'wcvendors');
        ?>
 <span
							class="description">(<?php 
        _e('required', 'wcvendors');
        ?>
)</span></label></th>
				<td><input type="email" name="pv_paypal" id="pv_paypal"
						   value="<?php 
        echo get_user_meta($user->ID, 'pv_paypal', true);
        ?>
" class="regular-text">
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_paypal', $user);
        ?>
			<tr>
				<th><label for="pv_custom_commission_rate"><?php 
        _e('Commission rate', 'wcvendors');
        ?>
 (%)</label></th>
				<td><input type="number" step="0.01" max="100" min="0" name="pv_custom_commission_rate" placeholder="<?php 
        _e('Leave blank for default', 'wcvendors');
        ?>
" id="pv_custom_commission_rate"
						   value="<?php 
        echo get_user_meta($user->ID, 'pv_custom_commission_rate', true);
        ?>
" class="regular-text">
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_commission_due', $user);
        ?>
			<tr>
				<th><label for="wcv_give_vendor_tax"><?php 
        _e('Give Tax', 'wcvendors');
        ?>
 (%)</label></th>
				<td>
					<label for="wcv_give_vendor_tax">
						<input name="wcv_give_vendor_tax" type="checkbox"
							   id="wcv_give_vendor_tax" <?php 
        checked(true, get_user_meta($user->ID, 'wcv_give_vendor_tax', true), $echo = true);
        ?>
/>
						<?php 
        _e('Tax override for vendor', 'wcvendors');
        ?>
					</label>
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_give_tax', $user);
        ?>
			<tr>
				<th><label for="wcv_give_vendor_shipping"><?php 
        _e('Give Shipping', 'wcvendors');
        ?>
 (%)</label></th>
				<td>
					<label for="wcv_give_vendor_shipping">
						<input name="wcv_give_vendor_shipping" type="checkbox"
							   id="wcv_give_vendor_shipping" <?php 
        checked(true, get_user_meta($user->ID, 'wcv_give_vendor_shipping', true), $echo = true);
        ?>
/>
						<?php 
        _e('Shipping override for vendor', 'wcvendors');
        ?>
					</label>
				</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_give_shipping', $user);
        ?>
			<tr>
				<th><label for="pv_seller_info"><?php 
        _e('Seller info', 'wcvendors');
        ?>
</label></th>
				<td><?php 
        wp_editor(get_user_meta($user->ID, 'pv_seller_info', true), 'pv_seller_info');
        ?>
</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_seller_info', $user);
        ?>
			<tr>
				<th><label for="pv_shop_description"><?php 
        _e('Shop description', 'wcvendors');
        ?>
</label>
				</th>
				<td><?php 
        wp_editor(get_user_meta($user->ID, 'pv_shop_description', true), 'pv_shop_description');
        ?>
</td>
			</tr>
			<?php 
        do_action('wcvendors_admin_after_shop_description', $user);
        ?>
			</tbody>
		</table>
	<?php 
    }
Example #17
0
 public function template_loop_sold_by($product_id)
 {
     $author = WCV_Vendors::get_vendor_from_product($product_id);
     $sold_by = WCV_Vendors::is_vendor($author) ? sprintf('<a href="%s">%s</a>', WCV_Vendors::get_vendor_shop_page($author), WCV_Vendors::get_vendor_shop_name($author)) : get_bloginfo('name');
     echo '<small>' . apply_filters('wcvendors_sold_by_in_loop', __('Sold by: ', 'wcvendors')) . $sold_by . '</small> <br />';
 }
 /**
  *
  *
  * @param unknown $menu
  *
  * @return unknown
  */
 public function show_pending_number($menu)
 {
     $args = array('post_type' => 'product', 'author' => get_current_user_id(), 'post_status' => 'pending');
     if (!WCV_Vendors::is_vendor(get_current_user_id())) {
         unset($args['author']);
     }
     $pending_posts = get_posts($args);
     $pending_count = is_array($pending_posts) ? count($pending_posts) : 0;
     $menu_str = 'edit.php?post_type=product';
     foreach ($menu as $menu_key => $menu_data) {
         if ($menu_str != $menu_data[2]) {
             continue;
         }
         if ($pending_count > 0) {
             $menu[$menu_key][0] .= " <span class='update-plugins counting-{$pending_count}'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
         }
     }
     return $menu;
 }
                     <span class="header-text accounts"><?php 
    _e("My Account", ',mango');
    ?>
</span>
					  <i class="icon-user"></i>
                     </a>
                  </li>
                  <?php 
}
?>
                  <?php 
if (is_user_logged_in()) {
    ?>

                  <?php 
    if (WCV_Vendors::is_vendor(get_current_user_id())) {
        ?>
                  <?php 
        if ($dashboard_id = WC_Vendors::$pv_options->get_option('vendor_dashboard_page')) {
            ?>
                  <li>
                     <a rel="nofollow" href="<?php 
            echo get_permalink($dashboard_id);
            ?>
">
                     <?php 
            _e('My Dashboard', 'mango');
            ?>
                     <i class="icon-speedometer"></i>
                     </a>
                  </li>
 public static function add_vendor_to_order_item_meta($item_id, $cart_item)
 {
     $vendor_id = $cart_item['data']->post->post_author;
     $sold_by = WCV_Vendors::is_vendor($vendor_id) ? sprintf(WCV_Vendors::get_vendor_sold_by($vendor_id)) : get_bloginfo('name');
     wc_add_order_item_meta($item_id, apply_filters('wcvendors_sold_by_in_email', __('Sold by : ', 'wcvendors')), $sold_by);
 }
 /**
  *
  *
  * @param unknown $order
  *
  * @return unknown
  */
 public function get_vendors($order)
 {
     $items = $order->get_items();
     $vendors = array();
     foreach ($items as $key => $product) {
         if (empty($product['product_id'])) {
             continue;
         }
         $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
         // Only store the vendor authors
         if (!WCV_Vendors::is_vendor($author)) {
             unset($items[$key]);
             continue;
         }
         $vendors[$author] = get_userdata($author)->user_email;
     }
     return $vendors;
 }
Example #22
0
 /**
  *
  *
  * @param unknown $order
  * @param unknown $group (optional)
  *
  * @return unknown
  */
 public static function get_vendor_dues_from_order($order, $group = true)
 {
     global $woocommerce;
     $give_tax = WC_Vendors::$pv_options->get_option('give_tax');
     $give_shipping = WC_Vendors::$pv_options->get_option('give_shipping');
     $receiver = array();
     $shipping_given = 0;
     $tax_given = 0;
     WCV_Shipping::$pps_shipping_costs = array();
     foreach ($order->get_items() as $key => $product) {
         $product_id = !empty($product['variation_id']) ? $product['variation_id'] : $product['product_id'];
         $author = WCV_Vendors::get_vendor_from_product($product_id);
         $give_tax_override = get_user_meta($author, 'wcv_give_vendor_tax', true);
         $give_shipping_override = get_user_meta($author, 'wcv_give_vendor_shipping', true);
         $is_vendor = WCV_Vendors::is_vendor($author);
         $commission = $is_vendor ? WCV_Commission::calculate_commission($product['line_subtotal'], $product_id, $order) : 0;
         $tax = !empty($product['line_tax']) ? (double) $product['line_tax'] : 0;
         // Check if shipping is enabled
         if (get_option('woocommerce_calc_shipping') === 'no') {
             $shipping = 0;
             $shipping_tax = 0;
         } else {
             $shipping_costs = WCV_Shipping::get_shipping_due($order->id, $product, $author);
             $shipping = $shipping_costs['amount'];
             $shipping_tax = $shipping_costs['tax'];
         }
         // Add line item tax and shipping taxes together
         $total_tax = (double) $tax + (double) $shipping_tax;
         // Tax override on a per vendor basis
         if ($give_tax_override) {
             $give_tax = true;
         }
         // Shipping override
         if ($give_shipping_override) {
             $give_shipping = true;
         }
         if ($is_vendor) {
             $shipping_given += $give_shipping ? $shipping : 0;
             $tax_given += $give_tax ? $total_tax : 0;
             $give = 0;
             $give += !empty($receiver[$author]['total']) ? $receiver[$author]['total'] : 0;
             $give += $give_shipping ? $shipping : 0;
             $give += $commission;
             $give += $give_tax ? $total_tax : 0;
             if ($group) {
                 $receiver[$author] = array('vendor_id' => (int) $author, 'commission' => !empty($receiver[$author]['commission']) ? $receiver[$author]['commission'] + $commission : $commission, 'shipping' => $give_shipping ? !empty($receiver[$author]['shipping']) ? $receiver[$author]['shipping'] + $shipping : $shipping : 0, 'tax' => $give_tax ? !empty($receiver[$author]['tax']) ? $receiver[$author]['tax'] + $total_tax : $total_tax : 0, 'qty' => !empty($receiver[$author]['qty']) ? $receiver[$author]['qty'] + $product['qty'] : $product['qty'], 'total' => $give);
             } else {
                 $receiver[$author][$key] = array('vendor_id' => (int) $author, 'product_id' => $product_id, 'commission' => $commission, 'shipping' => $give_shipping ? $shipping : 0, 'tax' => $give_tax ? $total_tax : 0, 'qty' => $product['qty'], 'total' => ($give_shipping ? $shipping : 0) + $commission + ($give_tax ? $total_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][$key] = 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 = round($order->order_tax + $order->order_shipping_tax - $tax_given, 2);
     $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][$key]['commission'] = $receiver[1][$key]['commission'] - $discount;
         $receiver[1][$key]['shipping'] = $order->order_shipping - $shipping_given;
         $receiver[1][$key]['tax'] = $tax;
         $receiver[1][$key]['total'] += $total;
     }
     // Reset the array keys
     // $receivers = array_values( $receiver );
     return $receiver;
 }
<?php

/**
 * Related Products
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $product, $woocommerce_loop;
if (empty($product) || !$product->exists()) {
    return;
}
global $post;
if (!WCV_Vendors::is_vendor($post->post_author)) {
    return;
}
$meta_query = WC()->query->get_meta_query();
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => 4, 'author' => get_the_author_meta('ID'), 'meta_query' => $meta_query, 'orderby' => 'rand');
$products = new WP_Query($args);
$woocommerce_loop['columns'] = 4;
if ($products->have_posts()) {
    ?>

	<div class="related products">

		<h2><?php 
    _e('More from this seller&hellip;', 'tokopress');
    ?>
</h2>