Beispiel #1
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;
 }
 function manage_commissions_column_content($column, $order_id)
 {
     if ('commissions' == $column) {
         $order = new WC_Order($order_id);
         $dues = WCV_Vendors::get_vendor_dues_from_order($order, false);
         foreach ($dues as $vendor_id => $details) {
             /*
             				$commission = 0;
             				$shipping = 0;
             				$tax = 0;*/
             $total = 0;
             foreach ($details as $value) {
                 /*
                 					$commission += $value['commission'];
                 					$shipping += $value['shipping'];
                 					$tax += $value['tax'];*/
                 $total += $value['total'];
             }
             echo sprintf("%01.2f&nbsp;€ ", $total);
             $vendor = get_user_by('id', $vendor_id);
             echo __('for', 'wcvendors') . ' <a href="/wp-admin/user-edit.php?user_id=' . $vendor_id . '">' . $vendor->display_name . '</a>';
             echo '<br />';
         }
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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/>';
 }
 /**
  *
  *
  * @param unknown $products
  *
  * @return unknown
  */
 public function filter_products_json($products)
 {
     $vendor_products = WCV_Vendors::get_vendor_products($this->vendor_id);
     $ids = array();
     foreach ($vendor_products as $vendor_product) {
         $ids[$vendor_product->ID] = $vendor_product->post_title;
     }
     return array_intersect_key($products, $ids);
 }
 public function filter_comment($commentdata, $order)
 {
     $user_id = get_current_user_id();
     $commentdata['user_id'] = $user_id;
     $commentdata['comment_author'] = WCV_Vendors::get_vendor_shop_name($user_id);
     $commentdata['comment_author_url'] = WCV_Vendors::get_vendor_shop_page($user_id);
     $commentdata['comment_author_email'] = wp_get_current_user()->user_email;
     return $commentdata;
 }
 function settings_page()
 {
     $user_id = get_current_user_id();
     $paypal_address = true;
     $shop_description = true;
     $description = get_user_meta($user_id, 'pv_shop_description', true);
     $seller_info = get_user_meta($user_id, 'pv_seller_info', true);
     $has_html = get_user_meta($user_id, 'pv_shop_html_enabled', true);
     $shop_page = WCV_Vendors::get_vendor_shop_page(wp_get_current_user()->user_login);
     $global_html = WC_Vendors::$pv_options->get_option('shop_html_enabled');
     include 'views/html-vendor-settings-page.php';
 }
 /**
  * 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());
 }
 /**
  *
  *
  * @param unknown $items
  * @param unknown $order
  *
  * @return unknown
  */
 public function check_items($items, $order)
 {
     foreach ($items as $key => $product) {
         if (empty($product['product_id'])) {
             unset($items[$key]);
             continue;
         }
         $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
         if ($this->current_vendor != $author) {
             unset($items[$key]);
             continue;
         }
     }
     return $items;
 }
Beispiel #10
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());
 }
</h2>
    <?php 
}
?>

	<div class="wcv_shop_description">
		<?php 
echo wpautop($shop_description);
?>
	</div>

	<?php 
if (of_get_option('tokopress_wcvendors_shop_profile') != 'no') {
    ?>
        <?php 
    $author = WCV_Vendors::get_vendor_from_product(get_the_ID());
    $user = get_userdata($author);
    ?>
        <p class="user-social">
        <?php 
    if ($user->facebook_url) {
        ?>
            <span class="user-facebook"><a rel="nofollow" href="<?php 
        echo esc_url($user->facebook_url);
        ?>
"><i class="fa fa-facebook"></i></a></span>
        <?php 
    }
    ?>

        <?php 
Beispiel #13
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();
 }
Beispiel #14
0
    $vendor_profile = of_get_option('tokopress_wcvendors_product_profile') != 'no' ? true : false;
}
$vendor = get_userdata($vendor_id);
if (!$vendor) {
    return;
}
$vendor_display_name = WC_Vendors::$pv_options->get_option('vendor_display_name');
switch ($vendor_display_name) {
    case 'display_name':
        $vendor_name = $vendor->display_name;
        break;
    case 'user_login':
        $vendor_name = $vendor->user_login;
        break;
    default:
        $vendor_name = WCV_Vendors::get_vendor_shop_name($vendor_id);
        break;
}
$vendor_description = do_shortcode(get_user_meta($vendor_id, 'pv_shop_description', true));
$has_html = get_user_meta($vendor_id, 'pv_shop_html_enabled', true);
$global_html = WC_Vendors::$pv_options->get_option('shop_html_enabled');
$store_banner = get_user_meta($vendor_id, 'tppv_shop_banner', true);
$store_info = '';
if ($vendor_name) {
    $store_info .= '<li class="store-name">' . esc_html($vendor_name) . '</li>';
}
if (trim($vendor_description)) {
    $store_info .= '<li class="store-description">' . ($global_html || $has_html) ? wpautop(wptexturize(wp_kses_post($vendor_description))) : sanitize_text_field($vendor_description) . '</li>';
}
$store_contact = '';
if ($vendor_profile) {
 /**
  *
  *
  * @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;
 }
 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);
 }
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>';
        }
    }
}
 /**
  *
  *
  * @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;
 }
Beispiel #19
0
 /**
  *
  *
  * @param unknown $order
  * @param unknown $author_email
  * @param unknown $setPaymentOptionsRequest
  * @param unknown $is_admin (optional)
  *
  * @return unknown
  */
 public function set_vendor_items($order, $setPaymentOptionsRequest)
 {
     $receivers = WCV_Vendors::get_vendor_dues_from_order($order, false);
     $receivers_two = WCV_Vendors::get_vendor_dues_from_order($order);
     foreach ($receivers as $products) {
         $invoice_items = array();
         $shipping_given = $tax_given = 0;
         foreach ($products as $key => $product) {
             $product_id = $product['product_id'];
             $shipping_given += $product['shipping'];
             $tax_given += $product['tax'];
             $product['commission'] = round($product['commission'], 2);
             if (!empty($product['commission'])) {
                 $item = new InvoiceItem();
                 $item->name = get_the_title($product_id);
                 $item->identifier = $product_id;
                 $item->price = $product['commission'];
                 $item->itemPrice = round($product['commission'] / $product['qty'], 2);
                 $item->itemCount = $product['qty'];
                 $invoice_items[] = $item;
             }
         }
         if (empty($invoice_items)) {
             continue;
         }
         $receiverOptions = new ReceiverOptions();
         $setPaymentOptionsRequest->receiverOptions[] = $receiverOptions;
         // Set the current vendor
         $receiverId = new ReceiverIdentifier();
         $receiverId->email = $product['vendor_id'] == 1 ? $this->main_paypal : WCV_Vendors::get_vendor_paypal($product['vendor_id']);
         $receiverOptions->receiver = $receiverId;
         $receiverOptions->invoiceData = new InvoiceData();
         $receiverOptions->invoiceData->item = $invoice_items;
         $receiverOptions->invoiceData->totalTax = number_format($receivers_two[$product['vendor_id']]['tax'], 2);
         $receiverOptions->invoiceData->totalShipping = number_format($receivers_two[$product['vendor_id']]['shipping'], 2);
     }
     return $setPaymentOptionsRequest;
 }
    /**
     *
     */
    function sales()
    {
        global $start_date, $end_date, $woocommerce, $wpdb;
        $start_date = !empty($_POST['start_date']) ? $_POST['start_date'] : strtotime(date('Ymd', strtotime(date('Ym', current_time('timestamp')) . '01')));
        $end_date = !empty($_POST['end_date']) ? $_POST['end_date'] : strtotime(date('Ymd', current_time('timestamp')));
        if (!empty($_POST['start_date'])) {
            $start_date = strtotime($_POST['start_date']);
        }
        if (!empty($_POST['end_date'])) {
            $end_date = strtotime($_POST['end_date']);
        }
        $after = date('Y-m-d', $start_date);
        $before = date('Y-m-d', strtotime('+1 day', $end_date));
        $commission_due = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'due'\n\t\t\tAND     time >= '" . $after . "'\n\t\t\tAND     time <= '" . $before . "'\n\t\t");
        $reversed = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'reversed'\n\t\t\tAND     time >= '" . $after . "'\n\t\t\tAND     time <= '" . $before . "'\n\t\t");
        $paid = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'paid'\n\t\t\tAND     time >= '" . $after . "'\n\t\t\tAND     time <= '" . $before . "'\n\t\t");
        ?>

		<form method="post" action="">
			<p><label for="from"><?php 
        _e('From:', 'wcvendors');
        ?>
</label> 
			<input type="text" size="9" placeholder="yyyy-mm-dd" value="<?php 
        echo esc_attr(date('Y-m-d', $start_date));
        ?>
" name="start_date" class="range_datepicker from" id="from" />
			<label for="to"><?php 
        _e('To:', 'wcvendors');
        ?>
</label> 
			<input type="text" size="9" placeholder="yyyy-mm-dd" value="<?php 
        echo esc_attr(date('Y-m-d', $end_date));
        ?>
" name="end_date" class="range_datepicker to" id="to" />
			<input type="submit" class="button" value="<?php 
        _e('Show', 'wcvendors');
        ?>
"/></p>
		</form>

		<div id="poststuff" class="woocommerce-reports-wrap">
			<div class="woocommerce-reports-sidebar">
				<div class="postbox">
					<h3><span><?php 
        _e('Total paid in range', 'wcvendors');
        ?>
</span></h3>

					<div class="inside">
						<p class="stat"><?php 
        if ($paid > 0) {
            echo woocommerce_price($paid);
        } else {
            _e('n/a', 'wcvendors');
        }
        ?>
</p>
					</div>
				</div>
				<div class="postbox">
					<h3><span><?php 
        _e('Total due in range', 'wcvendors');
        ?>
</span></h3>

					<div class="inside">
						<p class="stat"><?php 
        if ($commission_due > 0) {
            echo woocommerce_price($commission_due);
        } else {
            _e('n/a', 'wcvendors');
        }
        ?>
</p>
					</div>
				</div>
				<div class="postbox">
					<h3><span><?php 
        _e('Total reversed in range', 'wcvendors');
        ?>
</span></h3>

					<div class="inside">
						<p class="stat"><?php 
        if ($reversed > 0) {
            echo woocommerce_price($reversed);
        } else {
            _e('n/a', 'wcvendors');
        }
        ?>
</p>
					</div>
				</div>
			</div>

			<div class="woocommerce-reports-main">
				<div class="postbox">
					<h3><span><?php 
        _e('Recent Commission', 'wcvendors');
        ?>
</span></h3>

					<div>
						<?php 
        $commission = $wpdb->get_results("\n\t\t\t\t\t\t\t\tSELECT * FROM {$wpdb->prefix}pv_commission\n\t\t\t\t\t\t\t\tWHERE     time >= '" . $after . "'\n\t\t\t\t\t\t\t\tAND     time <= '" . $before . "'\n\t\t\t\t\t\t\t\tORDER BY time DESC\n\t\t\t\t\t\t\t");
        if (sizeof($commission) > 0) {
            ?>
							<div class="woocommerce_order_items_wrapper">
								<table id="commission-table" class="woocommerce_order_items" cellspacing="0">
									<thead>
									<tr>
										<th><?php 
            _e('Order', 'wcvendors');
            ?>
</th>
										<th><?php 
            _e('Product', 'wcvendors');
            ?>
</th>
										<th><?php 
            _e('Vendor', 'wcvendors');
            ?>
</th>
										<th><?php 
            _e('Total', 'wcvendors');
            ?>
</th>
										<th><?php 
            _e('Date &amp; Time', 'wcvendors');
            ?>
</th>
										<th><?php 
            _e('Status', 'wcvendors');
            ?>
</th>
									</tr>
									</thead>
									<tbody>
									<?php 
            $i = 1;
            foreach ($commission as $row) {
                $i++;
                ?>
										<tr<?php 
                if ($i % 2 == 1) {
                    echo ' class="alternate"';
                }
                ?>
>
											<td><?php 
                if ($row->order_id) {
                    ?>
<a
													href="<?php 
                    echo admin_url('post.php?post=' . $row->order_id . '&action=edit');
                    ?>
"><?php 
                    echo $row->order_id;
                    ?>
</a><?php 
                } else {
                    _e('N/A', 'wcvendors');
                }
                ?>
											</td>
											<td><?php 
                echo get_the_title($row->product_id);
                ?>
</td>
											<td><?php 
                echo WCV_Vendors::get_vendor_shop_name($row->vendor_id);
                ?>
</td>
											<td><?php 
                echo woocommerce_price($row->total_due + $row->total_shipping + $row->tax);
                ?>
</td>
											<td><?php 
                echo date(__('D j M Y \\a\\t h:ia', 'wcvendors'), strtotime($row->time));
                ?>
</td>
											<td><?php 
                echo $row->status;
                ?>
</td>
										</tr>
									<?php 
            }
            ?>
									</tbody>
								</table>
							</div>
						<?php 
        } else {
            ?>
<p><?php 
            _e('No commission yet', 'wcvendors');
            ?>
</p><?php 
        }
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
 /**
  * column_default function.
  *
  * @access public
  *
  * @param unknown $item
  * @param mixed   $column_name
  *
  * @return unknown
  */
 function column_default($item, $column_name)
 {
     global $wpdb;
     switch ($column_name) {
         case 'id':
             return $item->id;
         case 'vendor_id':
             $user = get_userdata($item->vendor_id);
             return '<a href="' . admin_url('user-edit.php?user_id=' . $item->vendor_id) . '">' . WCV_Vendors::get_vendor_shop_name($item->vendor_id) . '</a>';
         case 'total_due':
             return woocommerce_price($item->total_due + $item->total_shipping + $item->tax);
         case 'product_id':
             $parent = get_post_ancestors($item->product_id);
             $product_id = $parent ? $parent[0] : $item->product_id;
             return '<a href="' . admin_url('post.php?post=' . $product_id . '&action=edit') . '">' . get_the_title($item->product_id) . '</a>';
         case 'order_id':
             return '<a href="' . admin_url('post.php?post=' . $item->order_id . '&action=edit') . '">' . $item->order_id . '</a>';
         case 'status':
             return $item->status;
         case 'time':
             return date_i18n(get_option('date_format'), strtotime($item->time));
     }
 }
function tpvc_wc_mini_wcvendors_shortcode($atts)
{
    if (!class_exists('woocommerce')) {
        return;
    }
    if (!class_exists('WC_Vendors')) {
        return;
    }
    extract(shortcode_atts(array('tpvc_wc_vendor_title' => 'Vendors', 'tpvc_wc_vendor_title_color' => '', 'tpvc_wc_vendor_title_bg' => '', 'tpvc_wc_vendor_title_icon' => '', 'tpvc_wc_vendor_title_icon_color' => '', 'tpvc_wc_vendor_numbers' => 36, 'tpvc_wc_vendor_columns' => 12, 'tpvc_wc_vendor_columns_tablet' => 9, 'tpvc_wc_vendor_columns_mobile' => 4, 'tpvc_wc_vendor_orderby' => 'registered', 'tpvc_wc_vendor_order' => 'asc', 'tpvc_wc_vendor_hide_title' => '', 'tpvc_wc_vendor_show_products' => 'no', 'tpvc_wc_vendor_class' => ''), $atts));
    $meta_query = WC()->query->get_meta_query();
    if (intval($tpvc_wc_vendor_numbers) < 1) {
        $tpvc_wc_vendor_numbers = 36;
    }
    if (intval($tpvc_wc_vendor_columns) < 1) {
        $tpvc_wc_vendor_columns = 12;
    }
    if (intval($tpvc_wc_vendor_columns_tablet) < 1) {
        $tpvc_wc_vendor_columns_tablet = 9;
    }
    if (intval($tpvc_wc_vendor_columns_mobile) < 1) {
        $tpvc_wc_vendor_columns_mobile = 4;
    }
    $tpvc_wc_vendor_class .= ' tpvc-mini-product-col-md-' . $tpvc_wc_vendor_columns;
    $tpvc_wc_vendor_class .= ' tpvc-mini-product-col-sm-' . $tpvc_wc_vendor_columns_tablet;
    $tpvc_wc_vendor_class .= ' tpvc-mini-product-col-xs-' . $tpvc_wc_vendor_columns_mobile;
    $paged = 1;
    $offset = 0;
    // $paged      = (get_query_var('paged')) ? get_query_var('paged') : 1;
    // $offset     = ($paged - 1) * $per_page;
    // Hook into the user query to modify the query to return users that have at least one product
    if ($tpvc_wc_vendor_show_products == 'yes') {
        add_action('pre_user_query', array($this, 'vendors_with_products'));
    }
    // Get all vendors
    // 	$vendor_total_args = array (
    // 		'role' 				=> 'vendor',
    // 		'meta_key' 			=> 'pv_shop_slug',
    // 	'meta_value'   		=> '',
    // 'meta_compare' 		=> '>',
    // 'orderby' 			=> $tpvc_wc_vendor_orderby,
    // 	'order'				=> $tpvc_wc_vendor_order,
    // 	);
    // 	if ($tpvc_wc_vendor_show_products == 'yes') $vendor_total_args['query_id'] = 'vendors_with_products';
    // 	$vendor_query = New WP_User_Query( $vendor_total_args );
    // 	$all_vendors =$vendor_query->get_results();
    // Get the paged vendors
    $vendor_paged_args = array('role' => 'vendor', 'meta_key' => 'pv_shop_slug', 'meta_value' => '', 'meta_compare' => '>', 'orderby' => $tpvc_wc_vendor_orderby, 'order' => $tpvc_wc_vendor_order, 'offset' => $offset, 'number' => $tpvc_wc_vendor_numbers);
    if ($tpvc_wc_vendor_show_products == 'yes') {
        $vendor_total_args['query_id'] = 'vendors_with_products';
    }
    $vendor_paged_query = new WP_User_Query($vendor_paged_args);
    $paged_vendors = $vendor_paged_query->get_results();
    // Pagination calcs
    // $total_vendors = count($all_vendors);
    // $total_vendors_paged = count($paged_vendors);
    // $total_pages = intval($total_vendors / $per_page) + 1;
    ob_start();
    if (!empty($paged_vendors)) {
        ?>

	<div class="tpvc-mini-product woocommerce <?php 
        echo $tpvc_wc_vendor_class;
        ?>
">

		<?php 
        if ("hide" != $tpvc_wc_vendor_hide_title) {
            ?>
			<div class="tpvc-title" <?php 
            if ("" !== $tpvc_wc_vendor_title_bg) {
                echo 'style="background-color:' . $tpvc_wc_vendor_title_bg . '"';
            }
            ?>
>
				<h2 <?php 
            if ("" !== $tpvc_wc_vendor_title_color) {
                echo 'style="color:' . $tpvc_wc_vendor_title_color . '"';
            }
            ?>
>
					<?php 
            if ("" != $tpvc_wc_vendor_title_icon) {
                echo '<i class="' . tpvc_icon($tpvc_wc_vendor_title_icon) . '" ' . ($tpvc_wc_vendor_title_icon_color ? 'style="color:' . $tpvc_wc_vendor_title_icon_color . '"' : '') . '></i>';
            }
            ?>
					<?php 
            echo $tpvc_wc_vendor_title;
            ?>
				</h2>
			</div>
		<?php 
        }
        ?>

		<ul class="products">

			<?php 
        foreach ($paged_vendors as $vendor) {
            ?>

				<?php 
            $vendor_link = WCV_Vendors::get_vendor_shop_page($vendor->ID);
            ?>
				<?php 
            $vendor_name = $vendor->pv_shop_name;
            ?>

				<li class="product">

					<?php 
            echo get_avatar($vendor->ID, 200);
            ?>

					<div class="mini-icon-view">
						<a href="<?php 
            echo esc_url($vendor_link);
            ?>
" title="<?php 
            echo esc_attr($vendor_name);
            ?>
">
							<i class="fa fa-search"></i>
						</a>
					</div>

				</li>

			<?php 
        }
        // end of the loop.
        ?>

		</ul>

	</div>

	<?php 
    }
    return ob_get_clean();
}
Beispiel #23
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;
 }
 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);
 }
    /**
     * 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 
    }
Beispiel #26
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));
         }
     }
 }
 /**
  *
  *
  * @param unknown $items
  * @param unknown $order
  *
  * @return unknown
  */
 function check_items($items, $order)
 {
     foreach ($items as $key => $product) {
         //  If this is a line item
         if ($product['type'] == 'line_item') {
             $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
             if ($this->current_vendor != $author) {
                 unset($items[$key]);
                 continue;
             } else {
                 $commission_due = WCV_Commission::calculate_commission($product['line_subtotal'], $product['product_id'], $order);
                 $items[$key]['line_subtotal'] = $commission_due;
                 $items[$key]['line_total'] = $commission_due;
                 // Don't display tax if give tax is not enabled.
                 // if ( !WC_Vendors::$pv_options->get_option( 'give_tax' ) ) {
                 // 	unset($items[ $key ][ 'line_tax' ]) ;
                 // }
             }
         }
     }
     return $items;
 }
 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 />';
 }
Beispiel #29
0
 public static function get_vendor_sold_by($vendor_id)
 {
     $vendor_display_name = WC_Vendors::$pv_options->get_option('vendor_display_name');
     $vendor = get_userdata($vendor_id);
     switch ($vendor_display_name) {
         case 'display_name':
             $display_name = $vendor->display_name;
             break;
         case 'user_login':
             $display_name = $vendor->user_login;
             break;
         case 'user_email':
             $display_name = $vendor->user_email;
             break;
         default:
             $display_name = WCV_Vendors::get_vendor_shop_name($vendor_id);
             break;
     }
     return $display_name;
 }
 /**
  * Product's commission rate in percentage form
  *
  * Eg: 50 for 50%
  *
  * @param int $product_id
  *
  * @return float
  */
 public static function get_commission_rate($product_id)
 {
     $commission = 0;
     $parent = get_post_ancestors($product_id);
     if ($parent) {
         $product_id = $parent[0];
     }
     $vendor_id = WCV_Vendors::get_vendor_from_product($product_id);
     $product_commission = get_post_meta($product_id, 'pv_commission_rate', true);
     $vendor_commission = WCV_Vendors::get_default_commission($vendor_id);
     $default_commission = WC_Vendors::$pv_options->get_option('default_commission');
     if ($product_commission != '' && $product_commission !== false) {
         $commission = $product_commission;
     } else {
         if ($vendor_commission != '' && $vendor_commission !== false) {
             $commission = $vendor_commission;
         } else {
             if ($default_commission != '' && $default_commission !== false) {
                 $commission = $default_commission;
             }
         }
     }
     return apply_filters('wcv_commission_rate_percent', $commission, $product_id);
 }