/**
  * trigger function.
  *
  * @access public
  * @return void
  */
 function trigger($order_id)
 {
     $vendors = get_vendor_from_an_order($order_id);
     if ($vendors) {
         foreach ($vendors as $vendor) {
             $vendor_obj = get_wcmp_vendor_by_term($vendor);
             $vendor_email = $vendor_obj->user_data->user_email;
             $vendor_id = $vendor_obj->term_id;
             if ($order_id && $vendor_email) {
                 $this->object = new WC_Order($order_id);
                 $this->find[] = '{order_date}';
                 $this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->order_date));
                 $this->find[] = '{order_number}';
                 $this->replace[] = $this->object->get_order_number();
                 $this->vendor_email = $vendor_email;
                 $this->vendor_id = $vendor_id;
                 $this->recipient = $vendor_email;
             }
             if (!$this->is_enabled() || !$this->get_recipient()) {
                 return;
             }
             $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
         }
     }
 }
 /**
  * trigger function.
  *
  * @access public
  *
  * @param Commission $commission Commission paid
  */
 function trigger($trans_id, $vendor_id)
 {
     if (!isset($trans_id) && !isset($vendor_id)) {
         return;
     }
     $this->vendor = get_wcmp_vendor_by_term($vendor_id);
     $commissions = get_post_meta($trans_id, 'commission_detail', true);
     $this->commissions = $commissions;
     $this->transaction_id = $trans_id;
     $this->recipient = $this->vendor->user_data->user_email;
     $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
 }
 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 function widget($args, $instance)
 {
     global $WCMp, $woocommerce, $post;
     extract($args, EXTR_SKIP);
     $vendor_id = false;
     $vendor = false;
     // Only show current vendor widget when showing a vendor's product(s)
     $show_widget = false;
     if (is_singular('product')) {
         $vendor = get_wcmp_product_vendors($post->ID);
         if ($vendor) {
             $show_widget = true;
         }
     }
     if (is_archive() && is_tax('dc_vendor_shop')) {
         $show_widget = true;
     }
     $hide_from_guests = !empty($instance['hide_from_guests']) ? true : false;
     if ($hide_from_guests) {
         $show_widget = is_user_logged_in();
     }
     if ($show_widget) {
         if (is_tax('dc_vendor_shop')) {
             $vendor_id = get_queried_object()->term_id;
             if ($vendor_id) {
                 $vendor = get_wcmp_vendor_by_term($vendor_id);
             }
         }
         $args = array('instance' => $instance, 'vendor' => isset($vendor) ? $vendor : false, 'current_user' => wp_get_current_user(), 'widget' => $this);
         // Before widget (defined by themes)
         echo $before_widget;
         // Set up widget title
         if ($instance['title']) {
             $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
         } else {
             $title = false;
         }
         // Display the widget title if one was input (before and after defined by themes).
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Action for plugins/themes to hook onto
         do_action($this->widget_cssclass . '_top');
         $WCMp->template->get_template('widget/quick-info.php', $args);
         // Action for plugins/themes to hook onto
         do_action($this->widget_cssclass . '_bottom');
         // After widget (defined by themes).
         echo $after_widget;
     }
 }
 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 function widget($args, $instance)
 {
     global $WCMp, $woocommerce;
     extract($args, EXTR_SKIP);
     $vendor_id = false;
     $vendor = false;
     // Only show current vendor widget when showing a vendor's product(s)
     $show_widget = true;
     if (is_singular('product')) {
         global $post;
         $vendor = get_wcmp_product_vendors($post->ID);
         if (!$vendor) {
             $show_widget = false;
         }
     }
     if (is_archive() && !is_tax('dc_vendor_shop')) {
         $show_widget = false;
     }
     if ($show_widget) {
         if (is_tax('dc_vendor_shop')) {
             $vendor_id = get_queried_object()->term_id;
             if ($vendor_id) {
                 $vendor = get_wcmp_vendor_by_term($vendor_id);
             }
         }
         if ($vendor) {
             // Set up widget title
             if ($instance['title']) {
                 $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
             } else {
                 $title = false;
             }
             // Before widget (defined by themes)
             echo $before_widget;
             // Display the widget title if one was input (before and after defined by themes).
             if ($title) {
                 echo $before_title . $title . $after_title;
             }
             // Action for plugins/themes to hook onto
             do_action($this->widget_cssclass . '_top');
             // Widget content
             $WCMp->template->get_template('widget/vendor-info.php', array('vendor' => $vendor));
             // Action for plugins/themes to hook onto
             do_action($this->widget_cssclass . '_bottom');
             // After widget (defined by themes).
             echo $after_widget;
         }
     }
 }
_e('Product', $WCMp->text_domain);
?>
</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
_e('Quantity', $WCMp->text_domain);
?>
</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
_e('Price', $WCMp->text_domain);
?>
</th>
		</tr>
	</thead>
	<tbody>
		<?php 
$vendor = get_wcmp_vendor_by_term($vendor_id);
$vendor_items_dtl = $vendor->vendor_order_item_table($order, $vendor_id, true);
echo $vendor_items_dtl;
?>
	</tbody>
</table>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
	<?php 
if ($totals = $order->get_order_item_totals()) {
    $i = 0;
    foreach ($totals as $total) {
        $i++;
        ?>
<tr>
					<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php 
        if ($i == 1) {
 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     global $WCMp, $woocommerce;
     extract($args, EXTR_SKIP);
     $vendor_id = false;
     $vendors = false;
     // Only show current vendor widget when showing a vendor's product(s)
     $show_widget = false;
     if (is_tax('dc_vendor_shop')) {
         $vendor_id = get_queried_object()->term_id;
         if ($vendor_id) {
             $vendor = get_wcmp_vendor_by_term($vendor_id);
             $show_widget = true;
         }
     }
     if (is_singular('product')) {
         global $post;
         $vendor = get_wcmp_product_vendors($post->ID);
         if ($vendor) {
             $show_widget = true;
         }
     }
     if ($show_widget && isset($vendor->id)) {
         $vendor_address_1 = get_user_meta($vendor->id, '_vendor_address_1', true);
         $vendor_address_2 = get_user_meta($vendor->id, '_vendor_address_2', true);
         $vendor_city = get_user_meta($vendor->id, '_vendor_city', true);
         $vendor_state = get_user_meta($vendor->id, '_vendor_state', true);
         $vendor_postcode = get_user_meta($vendor->id, '_vendor_postcode', true);
         $vendor_country = get_user_meta($vendor->id, '_vendor_country', true);
         $location = '';
         if ($vendor_address_1) {
             $location = $vendor_address_1 . ' ,';
         }
         if ($vendor_address_2) {
             $location .= $vendor_address_2 . ' ,';
         }
         if ($vendor_city) {
             $location .= $vendor_city . ' ,';
         }
         if ($vendor_state) {
             $location .= $vendor_state . ' ,';
         }
         if ($vendor_postcode) {
             $location .= $vendor_postcode . ' ,';
         }
         if ($vendor_country) {
             $location .= $vendor_country;
         }
         $args = array('instance' => $instance, 'gmaps_link' => esc_url(add_query_arg(array('q' => urlencode($location)), '//maps.google.com/')), 'location' => $location);
         // Set up widget title
         if ($instance['title']) {
             $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
         } else {
             $title = false;
         }
         // Before widget (defined by themes)
         echo $before_widget;
         // Display the widget title if one was input (before and after defined by themes).
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Action for plugins/themes to hook onto
         do_action($this->widget_cssclass . '_top');
         $WCMp->template->get_template('widget/store-location.php', $args);
         // Action for plugins/themes to hook onto
         do_action($this->widget_cssclass . '_bottom');
         // After widget (defined by themes).
         echo $after_widget;
     }
 }
    /**
     * Output the report
     */
    public function output_report()
    {
        global $wpdb, $woocommerce, $WCMp;
        $vendor = $vendor_id = $order_items = false;
        $ranges = array('year' => __('Year', $WCMp->text_domain), 'last_month' => __('Last Month', $WCMp->text_domain), 'month' => __('This Month', $WCMp->text_domain), '7day' => __('Last 7 Days', $WCMp->text_domain));
        $current_range = !empty($_GET['range']) ? sanitize_text_field($_GET['range']) : '7day';
        if (!in_array($current_range, array('custom', 'year', 'last_month', 'month', '7day'))) {
            $current_range = '7day';
        }
        $this->calculate_current_range($current_range);
        if (isset($_POST['vendor'])) {
            $vendor_id = $_POST['vendor'];
            $vendor = get_wcmp_vendor_by_term($vendor_id);
            if ($vendor) {
                $products = $vendor->get_products();
            }
            if (!empty($products)) {
                foreach ($products as $product) {
                    $chosen_product_ids[] = $product->ID;
                }
            }
        }
        if ($vendor_id && $vendor) {
            $option = '<option value="' . $vendor_id . '" selected="selected">' . $vendor->user_data->display_name . '</option>';
        } else {
            $option = '<option></option>';
        }
        $all_vendors = get_wcmp_vendors();
        $start_date_str = $this->start_date;
        $end_date_str = $this->end_date;
        $end_date_str = strtotime('+1 day', $end_date_str);
        $start_date = date("Y-m-d H:i:s", $start_date_str);
        $end_date = date("Y-m-d H:i:s", $end_date_str);
        $total_sales = $admin_earning = $vendor_report = $report_bk = array();
        $max_total_sales = $i = 0;
        if (isset($all_vendors) && !empty($all_vendors)) {
            foreach ($all_vendors as $all_vendor) {
                $chosen_product_ids = array();
                $vendor_id = $all_vendor->id;
                $vendor = get_wcmp_vendor($vendor_id);
                if ($vendor) {
                    $products = $vendor->get_products();
                }
                if (!empty($products)) {
                    foreach ($products as $product) {
                        $chosen_product_ids[] = $product->ID;
                    }
                }
                if ($chosen_product_ids && is_array($chosen_product_ids)) {
                    // Get titles and ID's related to product
                    $chosen_product_titles = array();
                    $children_ids = array();
                    foreach ($chosen_product_ids as $product_id) {
                        $children = (array) get_posts('post_parent=' . $product_id . '&fields=ids&post_status=any&numberposts=-1');
                        $children_ids = $children_ids + $children;
                        $chosen_product_titles[] = get_the_title($product_id);
                    }
                    // Get order items
                    $order_items = apply_filters('woocommerce_reports_product_sales_order_items', $wpdb->get_results("\n\t\t\t\t\t\tSELECT posts.ID as order_id, order_item_meta_2.meta_value as product_id, order_item_meta_1.meta_value as variation_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total\n\t\t\t\t\t\tFROM {$wpdb->prefix}woocommerce_order_items as order_items\n\t\t\t\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_1 ON order_items.order_item_id = order_item_meta_1.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID\n\t\t\t\n\t\t\t\t\t\tWHERE posts.post_type \t= 'shop_order'\n\t\t\t\t\t\tAND \torder_item_meta_2.meta_value IN ('" . implode("','", array_merge($chosen_product_ids, $children_ids)) . "')\n\t\t\t\t\t\tAND posts.post_status IN ('wc-pending','wc-processing','wc-on-hold','wc-completed','wc-cancelled','wc-refunded','wc-failed')\n\t\t\t\t\t\tAND \torder_items.order_item_type = 'line_item'\n\t\t\t\t\t\tAND \torder_item_meta.meta_key = '_qty'\n\t\t\t\t\t\tAND \torder_item_meta_2.meta_key = '_product_id'\n\t\t\t\t\t\tAND \torder_item_meta_1.meta_key = '_variation_id'\n\t\t\t\t\t\tAND \torder_item_meta_3.meta_key = '_line_total'\n\t\t\t\t\t\tAND   posts.post_date BETWEEN '" . $start_date . "' AND '" . $end_date . "'\n\t\t\t\t\t\tGROUP BY order_items.order_id\n\t\t\t\t\t\tORDER BY posts.post_date ASC\n\t\t\t\t\t"), array_merge($chosen_product_ids, $children_ids));
                    if ($order_items) {
                        foreach ($order_items as $order_item) {
                            if ($order_item->line_total == 0 && $order_item->item_quantity == 0) {
                                continue;
                            }
                            if ($order_item->variation_id != '0') {
                                $product_id = $order_item->variation_id;
                                $variation_id = $order_item->variation_id;
                            } else {
                                $product_id = $order_item->product_id;
                                $variation_id = 0;
                            }
                            $commissions = false;
                            $vendor_earnings = 0;
                            $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_item->order_id), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($product_id), 'compare' => 'LIKE')));
                            $commissions = get_posts($args);
                            if (!empty($commissions)) {
                                foreach ($commissions as $commission) {
                                    $vendor_earnings = $vendor_earnings + get_post_meta($commission->ID, '_commission_amount', true);
                                }
                            }
                            if ($vendor_earnings <= 0) {
                                continue;
                            }
                            $total_sales[$vendor_id] = isset($total_sales[$vendor_id]) ? $total_sales[$vendor_id] + $order_item->line_total : $order_item->line_total;
                            $admin_earning[$vendor_id] = isset($admin_earning[$vendor_id]) ? $admin_earning[$vendor_id] + $order_item->line_total - $vendor_earnings : $order_item->line_total - $vendor_earnings;
                            if ($total_sales[$vendor_id] > $max_total_sales) {
                                $max_total_sales = $total_sales[$vendor_id];
                            }
                        }
                    }
                }
                if (isset($total_sales[$vendor_id]) && isset($admin_earning[$vendor_id])) {
                    $vendor_report[$i]['vendor_id'] = $vendor_id;
                    $vendor_report[$i]['total_sales'] = $total_sales[$vendor_id];
                    $vendor_report[$i++]['admin_earning'] = $admin_earning[$vendor_id];
                    $report_bk[$vendor_id]['total_sales'] = $total_sales[$vendor_id];
                    $report_bk[$vendor_id]['admin_earning'] = $admin_earning[$vendor_id];
                }
            }
            $i = 0;
            $max_value = 10;
            $report_sort_arr = array();
            if (isset($vendor_report) && isset($report_bk)) {
                $total_sales_sort = wp_list_pluck($vendor_report, 'total_sales', 'vendor_id');
                $admin_earning_sort = wp_list_pluck($vendor_report, 'admin_earning', 'vendor_id');
                foreach ($total_sales_sort as $key => $value) {
                    $total_sales_sort_arr[$key]['total_sales'] = $report_bk[$key]['total_sales'];
                    $total_sales_sort_arr[$key]['admin_earning'] = $report_bk[$key]['admin_earning'];
                }
                arsort($total_sales_sort);
                foreach ($total_sales_sort as $key => $value) {
                    if ($i++ < $max_value) {
                        $report_sort_arr[$key]['total_sales'] = $report_bk[$key]['total_sales'];
                        $report_sort_arr[$key]['admin_earning'] = $report_bk[$key]['admin_earning'];
                    }
                }
            }
            wp_localize_script('wcmp_report_js', 'wcmp_report_vendor', array('vendor_report' => $vendor_report, 'report_bk' => $report_bk, 'total_sales_sort' => $total_sales_sort, 'admin_earning_sort' => $admin_earning_sort, 'max_total_sales' => $max_total_sales, 'start_date' => $start_date, 'end_date' => $end_date));
            $chart_arr = $html_chart = '';
            if (count($report_sort_arr) > 0) {
                foreach ($report_sort_arr as $vendor_id => $sales_report) {
                    $total_sales_width = $sales_report['total_sales'] > 0 ? $sales_report['total_sales'] / round($max_total_sales) * 100 : 0;
                    $admin_earning_width = $sales_report['admin_earning'] > 0 ? $sales_report['admin_earning'] / round($max_total_sales) * 100 : 0;
                    $user = get_userdata($vendor_id);
                    $user_name = $user->data->display_name;
                    $chart_arr .= '<tr><th><a href="user-edit.php?user_id=' . $vendor_id . '">' . $user_name . '</a></th>
					<td width="1%"><span>' . woocommerce_price($sales_report['total_sales']) . '</span><span class="alt">' . woocommerce_price($sales_report['admin_earning']) . '</span></td>
					<td class="bars">
						<span style="width:' . esc_attr($total_sales_width) . '%">&nbsp;</span>
						<span class="alt" style="width:' . esc_attr($admin_earning_width) . '%">&nbsp;</span>
					</td></tr>';
                }
                $html_chart = '
					<h4>' . __("Sales and Earnings", $WCMp->text_domain) . '</h4>
					<div class="bar_indecator">
						<div class="bar1">&nbsp;</div>
						<span class="">' . __('Gross Sales', $WCMp->text_domain) . '</span>
						<div class="bar2">&nbsp;</div>
						<span class="">' . __('My Earnings', $WCMp->text_domain) . '</span>
					</div>
					<table class="bar_chart">
						<thead>
							<tr>
								<th>' . __("Vendors", $WCMp->text_domain) . '</th>
								<th colspan="2">' . __("Sales Report", $WCMp->text_domain) . '</th>
							</tr>
						</thead>
						<tbody>
							' . $chart_arr . '
						</tbody>
					</table>
				';
            } else {
                $html_chart = '<tr><td colspan="3">' . __('Any vendor did not generate any sales in the given period.', $WCMp->text_domain) . '</td></tr>';
            }
        } else {
            $html_chart = '<tr><td colspan="3">' . __('Your store has no vendors.', $WCMp->text_domain) . '</td></tr>';
        }
        include $WCMp->plugin_path . '/classes/reports/views/html-wcmp-report-by-vendor.php';
    }
 *
 * Override this template by copying it to yourtheme/dc-product-vendor/shortcode/vendor_transaction_thankyou.php
 *
 * @author 		dualcube
 * @package 	WCMp/Templates
 * @version   2.2.0
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
global $WCMp;
$transaction_id = isset($_GET['transaction_id']) ? $_GET['transaction_id'] : false;
if ($transaction_id) {
    $transaction = get_post($transaction_id);
    $vendor = get_wcmp_vendor_by_term($transaction->post_author);
    ?>
<p><?php 
    echo apply_filters('wcmp_thankyou_transaction_received_text', sprintf(__('Hello,<br>We have received a new withdrawal request for $%s from you and Your request is being processed.The order details are as follow:', $WCMp->text_domain), get_post_meta($transaction_id, 'amount', true)), $transaction_id);
    ?>
</p>
<table cellspacing="0" cellpadding="6"  border="1" >
	<thead>
		<?php 
    $commission_details = $WCMp->transaction->get_transaction_item_details($transaction_id);
    ?>
		<tr>
			<?php 
    if (!empty($commission_details['header'])) {
        ?>
				<tr>
 /**
  * Create new commission post
  *
  * @param  int $vendor_id  ID of vendor for commission
  * @param  int $product_id ID of product for commission
  * @param  int $amount     Commission total
  * @return void
  */
 public function create_commission($vendor_id = 0, $product_id = 0, $amount = 0, $order_id = 0, $variation_id = 0, $item_id = 0, $item)
 {
     global $WCMp, $wpdb;
     if ($vendor_id == 0) {
         return;
     }
     if (!isset($amount['total'])) {
         $amount['total'] = 0;
     }
     if (!isset($amount['shipping'])) {
         $amount['shipping'] = 0;
     }
     if (!isset($amount['tax'])) {
         $amount['tax'] = 0;
     }
     if (!isset($amount['commission'])) {
         $amount['commission'] = 0;
     }
     $commission_data = array('post_type' => 'dc_commission', 'post_title' => sprintf(__('Commission - %s', $WCMp->text_domain), strftime(_x('%B %e, %Y @ %I:%M %p', 'Commission date parsed by strftime', $WCMp->text_domain))), 'post_status' => 'private', 'ping_status' => 'closed', 'post_excerpt' => '', 'post_author' => 1);
     $commission_id = wp_insert_post($commission_data);
     // Add meta data
     if ($vendor_id > 0) {
         update_post_meta($commission_id, '_commission_vendor', $vendor_id);
     }
     if ($variation_id > 0) {
         update_post_meta($commission_id, '_commission_product', array($variation_id));
     } else {
         update_post_meta($commission_id, '_commission_product', array($product_id));
     }
     update_post_meta($commission_id, '_commission_amount', $amount['commission']);
     update_post_meta($commission_id, '_shipping', $amount['shipping']);
     update_post_meta($commission_id, '_tax', $amount['tax']);
     if ($order_id > 0) {
         update_post_meta($commission_id, '_commission_order_id', $order_id);
     }
     // Mark commission as unpaid
     update_post_meta($commission_id, '_paid_status', 'unpaid');
     if ($variation_id > 0) {
         $com_pro_id = $variation_id;
     } else {
         $com_pro_id = $product_id;
     }
     $item_commission = $this->get_item_commission($product_id, $product_id, $item, $order_id, $item_id);
     $vendor = get_wcmp_vendor_by_term($vendor_id);
     $vendor_shipping_costs = $vendor->get_wcmp_vendor_shipping_total($order_id, $item);
     $item_shipping = $vendor_shipping_costs['shipping_amount'] + $vendor_shipping_costs['shipping_tax'];
     $item_tax = get_metadata('order_item', $item_id, '_line_tax', true);
     doProductVendorLOG("UPDATE `{$wpdb->prefix}wcmp_vendor_orders` \tSET commission_id = " . $commission_id . ", commission_amount = '" . $item_commission . "', `shipping` = '" . $item_shipping . "', `tax` = '" . $item_tax . "'\tWHERE order_id =" . $order_id . " AND order_item_id = " . $item_id . " AND product_id\t=" . $com_pro_id);
     $update_query = $wpdb->query("UPDATE `{$wpdb->prefix}wcmp_vendor_orders` \tSET commission_id = " . $commission_id . ", commission_amount = '" . $item_commission . "', `shipping` = '" . $item_shipping . "', `tax` = '" . $item_tax . "'\tWHERE order_id =" . $order_id . " AND order_item_id = " . $item_id . " AND product_id\t=" . $com_pro_id);
     do_action('wcmp_vendor_commission_created', $commission_id);
 }
Example #10
0
    /**
     * WCMp Vendor Data Searching
     */
    function search_vendor_data()
    {
        global $WCMp, $wpdb;
        $chosen_product_ids = $vendor_id = $vendor = false;
        $vendor_id = $_POST['vendor_id'];
        $start_date = $_POST['start_date'];
        $end_date = $_POST['end_date'];
        if ($vendor_id) {
            $vendor = get_wcmp_vendor_by_term($vendor_id);
            if ($vendor) {
                $products = $vendor->get_products();
            }
            if (!empty($products)) {
                foreach ($products as $product) {
                    $chosen_product_ids[] = $product->ID;
                }
            }
        }
        if ($vendor_id && empty($products)) {
            $no_vendor = '<h4>' . __("Sales and Earnings", $WCMp->text_domain) . '</h4>
			<table class="bar_chart">
				<thead>
					<tr>
						<th>' . __("Month", $WCMp->text_domain) . '</th>
						<th colspan="2">' . __("Sales", $WCMp->text_domain) . '</th>
					</tr>
				</thead>
				<tbody> 
					<tr><td colspan="3">' . __("No Sales :(", $WCMp->text_domain) . '</td></tr>
				</tbody>
			</table>';
            echo $no_vendor;
            die;
        }
        if ($chosen_product_ids && is_array($chosen_product_ids)) {
            // Get titles and ID's related to product
            $chosen_product_titles = array();
            $children_ids = array();
            foreach ($chosen_product_ids as $product_id) {
                $children = (array) get_posts('post_parent=' . $product_id . '&fields=ids&post_status=any&numberposts=-1');
                $children_ids = $children_ids + $children;
                $chosen_product_titles[] = get_the_title($product_id);
            }
            // Get order items
            $order_items = apply_filters('woocommerce_reports_product_sales_order_items', $wpdb->get_results("\n\t\t\t\tSELECT posts.ID as order_id, order_item_meta_2.meta_value as product_id, order_item_meta_1.meta_value as variation_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total\n\t\t\t\tFROM {$wpdb->prefix}woocommerce_order_items as order_items\n\t\n\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id\n\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_1 ON order_items.order_item_id = order_item_meta_1.order_item_id\n\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id\n\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id\n\t\t\t\tLEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID\n\t\n\t\t\t\tWHERE posts.post_type \t= 'shop_order'\n\t\t\t\tAND \torder_item_meta_2.meta_value IN ('" . implode("','", array_merge($chosen_product_ids, $children_ids)) . "')\n\t\t\t\tAND posts.post_status IN ('wc-pending','wc-processing','wc-on-hold','wc-completed','wc-cancelled','wc-refunded','wc-failed')\n\t\t\t\tAND \torder_items.order_item_type = 'line_item'\n\t\t\t\tAND \torder_item_meta.meta_key = '_qty'\n\t\t\t\tAND \torder_item_meta_2.meta_key = '_product_id'\n\t\t\t\tAND \torder_item_meta_1.meta_key = '_variation_id'\n\t\t\t\tAND \torder_item_meta_3.meta_key = '_line_total'\n\t\t\t\tAND   posts.post_date BETWEEN '" . $start_date . "' AND '" . $end_date . "'\n\t\t\t\tGROUP BY order_items.order_id\n\t\t\t\tORDER BY posts.post_date ASC\n\t\t\t"), array_merge($chosen_product_ids, $children_ids));
            $total_sales = $admin_earning = array();
            $max_total_sales = 0;
            if ($order_items) {
                foreach ($order_items as $order_item) {
                    if ($order_item->line_total == 0 && $order_item->item_quantity == 0) {
                        continue;
                    }
                    // Get date
                    $date = date('Ym', strtotime($order_item->post_date));
                    if ($order_item->variation_id != '0') {
                        $product_id = $order_item->variation_id;
                        $variation_id = $order_item->variation_id;
                    } else {
                        $product_id = $order_item->product_id;
                        $variation_id = 0;
                    }
                    $commissions = false;
                    $vendor_earnings = 0;
                    $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_item->order_id), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($product_id), 'compare' => 'LIKE')));
                    $commissions = get_posts($args);
                    if (!empty($commissions)) {
                        foreach ($commissions as $commission) {
                            $vendor_earnings = $vendor_earnings + get_post_meta($commission->ID, '_commission_amount', true);
                        }
                    }
                    if ($vendor_earnings <= 0) {
                        continue;
                    }
                    // Set values
                    $total_sales[$date] = isset($total_sales[$date]) ? $total_sales[$date] + $order_item->line_total : $order_item->line_total;
                    $admin_earning[$date] = isset($admin_earning[$date]) ? $admin_earning[$date] + $order_item->line_total - $vendor_earnings : $order_item->line_total - $vendor_earnings;
                    if ($total_sales[$date] > $max_total_sales) {
                        $max_total_sales = $total_sales[$date];
                    }
                }
            }
            $report_chart = $report_html = '';
            if (count($total_sales) > 0) {
                foreach ($total_sales as $date => $sales) {
                    $width = $sales > 0 ? round($sales) / round($max_total_sales) * 100 : 0;
                    $width2 = $admin_earning[$date] > 0 ? round($admin_earning[$date]) / round($max_total_sales) * 100 : 0;
                    $orders_link = admin_url('edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode(implode(' ', $chosen_product_titles)) . '&m=' . date('Ym', strtotime($date . '01')) . '&shop_order_status=' . implode(",", apply_filters('woocommerce_reports_order_statuses', array('completed', 'processing', 'on-hold'))));
                    $orders_link = apply_filters('woocommerce_reports_order_link', $orders_link, $chosen_product_ids, $chosen_product_titles);
                    $report_chart .= '<tr><th><a href="' . esc_url($orders_link) . '">' . date_i18n('F', strtotime($date . '01')) . '</a></th>
						<td width="1%"><span>' . woocommerce_price($sales) . '</span><span class="alt">' . woocommerce_price($admin_earning[$date]) . '</span></td>
						<td class="bars">
							<span class="main" style="width:' . esc_attr($width) . '%">&nbsp;</span>
							<span class="alt" style="width:' . esc_attr($width2) . '%">&nbsp;</span>
						</td></tr>';
                }
                $report_html = '
					<h4>' . $vendor_title . '</h4>
					<div class="bar_indecator">
						<div class="bar1">&nbsp;</div>
						<span class="">' . __("Gross Sales", $WCMp->text_domain) . '</span>
						<div class="bar2">&nbsp;</div>
						<span class="">' . __("My Earnings", $WCMp->text_domain) . '</span>
					</div>
					<table class="bar_chart">
						<thead>
							<tr>
								<th>' . __("Month", $WCMp->text_domain) . '</th>
								<th colspan="2">' . __("Vendor Earnings", $WCMp->text_domain) . '</th>
							</tr>
						</thead>
						<tbody>
							' . $report_chart . '
						</tbody>
					</table>
				';
            } else {
                $report_html = '<tr><td colspan="3">' . __('This vendor did not generate any sales in the given period.', $WCMp->text_domain) . '</td></tr>';
            }
        }
        echo $report_html;
        die;
    }
 /**
  * Create transaction from commissions
  *
  * @param array $commission_ids
  */
 function create_transactions($commission_ids)
 {
     global $WCMp;
     $transaction_datas = array();
     if (!empty($commission_ids)) {
         foreach ($commission_ids as $commission_id) {
             $vendor_id = get_post_meta($commission_id, '_commission_vendor', true);
             $vendor = get_wcmp_vendor_by_term($vendor_id);
             $paid_status = get_post_meta($commission_id, '_paid_status', true);
             $order_id = get_post_meta($commission_id, '_commission_order_id', true);
             $order = new WC_Order($order_id);
             $vendor_shipping = get_post_meta($commission_id, '_shipping', true);
             $vendor_tax = get_post_meta($commission_id, '_tax', true);
             $due_vendor = $vendor->wcmp_get_vendor_part_from_order($order, $vendor_id);
             if (!$vendor_shipping) {
                 $vendor_shipping = $due_vendor['shipping'];
             }
             if (!$vendor_tax) {
                 $vendor_tax = $due_vendor['tax'];
             }
             $amount = get_post_meta($commission_id, '_commission_amount', true);
             $vendor_due = 0;
             $vendor_due = (double) $amount + (double) $vendor_shipping + (double) $vendor_tax;
             $transaction_datas[$vendor_id]['commission_detail'][$commission_id] = $order_id;
             if (!isset($transaction_datas[$vendor_id]['amount'])) {
                 $transaction_datas[$vendor_id]['amount'] = $vendor_due;
             } else {
                 $transaction_datas[$vendor_id]['amount'] += $vendor_due;
             }
         }
         $this->insert_new_transaction($transaction_datas, 'wcmp_completed', 'manual');
     }
 }
    /**
     * Register and add settings
     */
    public function settings_page_init()
    {
        global $WCMp;
        //pending vendor
        $get_pending_vendors = get_users('role=dc_pending_vendor');
        if (!empty($get_pending_vendors)) {
            ?>
  	<h3><?php 
            _e('Pending Vendor Approval', $WCMp->text_domain);
            ?>
</h3>
  	<table class="form-table" id="to_do_list">
  		<tbody>
  			<tr>
					<th style="width:50%" ><?php 
            _e('Pending User', $WCMp->text_domain);
            ?>
 </th>
					<th><?php 
            _e('Edit', $WCMp->text_domain);
            ?>
</th>
					<th><?php 
            _e('Activate', $WCMp->text_domain);
            ?>
</th>
					<th><?php 
            _e('Reject', $WCMp->text_domain);
            ?>
</th>
					<th><?php 
            _e('Dismiss', $WCMp->text_domain);
            ?>
</th>
				</tr>
  			<?php 
            foreach ($get_pending_vendors as $pending_vendor) {
                $dismiss = get_user_meta($pending_vendor->ID, '_dismiss_to_do_list', true);
                if ($dismiss) {
                    continue;
                }
                ?>
					<tr>
						<td style="width:50%" class="username column-username"><img alt="" src="<?php 
                echo $WCMp->plugin_url . 'assets/images/wp-avatar-frau.jpg';
                ?>
" class="avatar avatar-32 photo" height="32" width="32"><?php 
                echo $pending_vendor->user_login;
                ?>
</td>
						<td class="edit"><a target="_blank" href="user-edit.php?user_id=<?php 
                echo $pending_vendor->ID;
                ?>
&amp;wp_http_referer=%2Fwordpress%2Fdc_vendor%2Fwp-admin%2Fusers.php%3Frole%3Ddc_pending_vendor"><input type="button" class="vendor_edit_button" value="Edit" /> </a> </td>
						<td class="activate"><input class="activate_vendor" type="button" class="activate_vendor" data-id="<?php 
                echo $pending_vendor->ID;
                ?>
" value="Activate" ></td> 
						<td class="reject"><input class="reject_vendor" type="button" class="reject_vendor" data-id="<?php 
                echo $pending_vendor->ID;
                ?>
" value="Reject"></td>
						<td class="dismiss"><input class="vendor_dismiss_button" type="button" data-type="user" data-id="<?php 
                echo $pending_vendor->ID;
                ?>
" id="dismiss_request" name="dismiss_request" value="Dismiss"></td>
					</tr>
				<?php 
            }
            ?>
  		</tbody>
  	</table>
  	<?php 
        }
        $vendors = get_wcmp_vendors();
        if ($vendors) {
            $vendor_ids = array();
            foreach ($vendors as $vendor) {
                $vendor_ids[] = $vendor->id;
            }
        }
        //coupon
        $args = array('posts_per_page' => -1, 'author__in' => $vendor_ids, 'post_type' => 'shop_coupon', 'post_status' => 'pending');
        $get_pending_coupons = new WP_Query($args);
        $get_pending_coupons = $get_pending_coupons->get_posts();
        if (!empty($get_pending_coupons)) {
            ?>
  	<h3><?php 
            _e('Pending Coupons Approval', $WCMp->text_domain);
            ?>
</h3>
  	<table class="form-table" id="to_do_list">
  		<tbody>
  			<tr>
					<th><?php 
            _e('Vendor Name', $WCMp->text_domain);
            ?>
 </th>
					<th><?php 
            _e('Coupon Name', $WCMp->text_domain);
            ?>
</th>
					<th><?php 
            _e('Edit', $WCMp->text_domain);
            ?>
</th>
					<th><?php 
            _e('Dismiss', $WCMp->text_domain);
            ?>
</th>
				</tr>
  			<?php 
            foreach ($get_pending_coupons as $get_pending_coupon) {
                $dismiss = get_post_meta($get_pending_coupon->ID, '_dismiss_to_do_list', true);
                if ($dismiss) {
                    continue;
                }
                ?>
					<tr>
						<?php 
                $currentvendor = get_userdata($get_pending_coupon->post_author);
                ?>
						<td class="coupon column-coupon"><a href="user-edit.php?user_id=<?php 
                echo $get_pending_coupon->post_author;
                ?>
&amp;wp_http_referer=%2Fwordpress%2Fdc_vendor%2Fwp-admin%2Fusers.php%3Frole%3Ddc_vendor" target="_blank"><?php 
                echo $currentvendor->display_name;
                ?>
</a></td>
						<td class="coupon column-coupon"><?php 
                echo $get_pending_coupon->post_title;
                ?>
</td>
						<td class="edit"><a target="_blank" href="post.php?post=<?php 
                echo $get_pending_coupon->ID;
                ?>
&action=edit"><input type="button" class="vendor_edit_button" value="Edit" /> </a> </td>
						<td class="dismiss"><input class="vendor_dismiss_button" type="button" data-type="shop_coupon" data-id="<?php 
                echo $get_pending_coupon->ID;
                ?>
" id="dismiss_request" name="dismiss_request" value="Dismiss"></td>
					</tr>
				<?php 
            }
            ?>
  		</tbody>
  	</table>
  	<?php 
        }
        //product
        $args = array('posts_per_page' => -1, 'author__in' => $vendor_ids, 'post_type' => 'product', 'post_status' => 'pending');
        $get_pending_products = new WP_Query($args);
        $get_pending_products = $get_pending_products->get_posts();
        if (!empty($get_pending_products)) {
            ?>
  	<h3><?php 
            _e('Pending Products Approval', $WCMp->text_domain);
            ?>
</h3>
  	<table class="form-table" id="to_do_list">
  		<tbody>
  			<tr>
						<th><?php 
            _e('Vendor Name', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Product Name', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Edit', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Dismiss', $WCMp->text_domain);
            ?>
</th>
				</tr>
  			<?php 
            foreach ($get_pending_products as $get_pending_product) {
                $dismiss = get_post_meta($get_pending_product->ID, '_dismiss_to_do_list', true);
                if ($dismiss) {
                    continue;
                }
                ?>
					<tr>
						<?php 
                $currentvendor = get_userdata($get_pending_product->post_author);
                ?>
						<td class="vendor column-coupon"><a href="user-edit.php?user_id=<?php 
                echo $get_pending_product->post_author;
                ?>
&amp;wp_http_referer=%2Fwordpress%2Fdc_vendor%2Fwp-admin%2Fusers.php%3Frole%3Ddc_vendor" target="_blank"><?php 
                echo $currentvendor->display_name;
                ?>
</a></td>
						<td class="coupon column-coupon"><?php 
                echo $get_pending_product->post_title;
                ?>
</td>
						<td class="edit"><a target="_blank" href="post.php?post=<?php 
                echo $get_pending_product->ID;
                ?>
&action=edit"><input type="button" class="vendor_edit_button" value="Edit" /> </a> </td>
						<td class="dismiss"><input class="vendor_dismiss_button" data-type="product" data-id="<?php 
                echo $get_pending_product->ID;
                ?>
"  type="button" id="dismiss_request" name="dismiss_request" value="Dismiss"></td>
					</tr>
				<?php 
            }
            ?>
  		</tbody>
  	</table>
  	<?php 
        }
        //commission
        $args = array('post_type' => 'wcmp_transaction', 'post_status' => 'wcmp_processing', 'meta_key' => 'transaction_mode', 'meta_value' => 'direct_bank', 'posts_per_page' => -1);
        $transactions = get_posts($args);
        if (!empty($transactions)) {
            ?>
  	<h3><?php 
            _e('Pending Bank Transfer', $WCMp->text_domain);
            ?>
</h3>
  	<table class="form-table" id="to_do_list">
  		<tbody>
  			<tr>
						<th><?php 
            _e('Vendor', $WCMp->text_domain);
            ?>
 </th>
						<th><?php 
            _e('Commission', $WCMp->text_domain);
            ?>
 </th>
						<th><?php 
            _e('Amount', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Account Detail', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Notify the Vendor', $WCMp->text_domain);
            ?>
</th>
						<th><?php 
            _e('Dismiss', $WCMp->text_domain);
            ?>
</th>
				</tr>
  			<?php 
            foreach ($transactions as $transaction) {
                $dismiss = get_post_meta($transaction->ID, '_dismiss_to_do_list', true);
                if ($dismiss) {
                    continue;
                }
                ?>
					<tr>
						<?php 
                $vendor_term_id = $transaction->post_author;
                $currentvendor = get_wcmp_vendor_by_term($vendor_term_id);
                $account_name = get_user_meta($currentvendor->id, '_vendor_account_holder_name', true);
                $account_no = get_user_meta($currentvendor->id, '_vendor_bank_account_number', true);
                $bank_name = get_user_meta($currentvendor->id, '_vendor_bank_name', true);
                $iban = get_user_meta($currentvendor->id, '_vendor_iban', true);
                $amount = get_post_meta($transaction->ID, 'amount', true);
                ?>
    
						<td class="vendor column-coupon"><a href="user-edit.php?user_id=<?php 
                echo $currentvendor->id;
                ?>
&amp;wp_http_referer=%2Fwordpress%2Fdc_vendor%2Fwp-admin%2Fusers.php%3Frole%3Ddc_vendor" target="_blank"><?php 
                echo $currentvendor->user_data->display_name;
                ?>
</a></td>
						<td class="commission column-coupon"><a href="post.php?post=<?php 
                echo $transaction->ID;
                ?>
&action=edit" target="_blank" ><?php 
                echo $transaction->post_title;
                ?>
</a></td>
						<td class="commission_val column-coupon"><?php 
                echo get_woocommerce_currency_symbol() . $amount;
                ?>
</td>
						<td class="account_detail"><?php 
                echo __('Account Name- ', $WCMp->text_domain) . ' ' . $account_name . '<br>' . __('Account No - ', $WCMp->text_domain) . $account_no . '<br>' . __('Bank Name - ', $WCMp->text_domain) . $bank_name . '<br>' . __('IBAN - ', $WCMp->text_domain) . $iban;
                ?>
</td>
						<td class="done"><input class="vendor_transaction_done_button" data-transid="<?php 
                echo $transaction->ID;
                ?>
" data-vendorid="<?php 
                echo $vendor_term_id;
                ?>
" type="button" id="done_request" name="done_request" value="Done"></td>
						<td class="dismiss"><input class="vendor_dismiss_button" data-type="dc_commission" data-id="<?php 
                echo $transaction->ID;
                ?>
" type="button" id="dismiss_request" name="dismiss_request" value="Dismiss"></td>
					</tr>
				<?php 
            }
            ?>
  		</tbody>
  	</table>
  	<?php 
        }
    }
 public function get_vendor_total_tax_and_shipping($order, $vendor_id, $product, $commission_obj)
 {
     $tax_amt = 0;
     $give_tax = false;
     $give_shipping = false;
     $vendor_items = $this->get_vendor_items_from_order($order->id, $vendor_id);
     $shipping_given = 0;
     $tax_given = 0;
     if (!empty($product)) {
         $product_id = !empty($product['variation_id']) ? $product['variation_id'] : $product['product_id'];
         $vendor_user = get_wcmp_vendor_by_term($vendor_id);
         $give_tax_override = get_user_meta($vendor_user->id, '_vendor_give_tax', true);
         $give_shipping_override = get_user_meta($vendor_user->id, '_vendor_give_shipping', true);
         $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 = $this->get_wcmp_vendor_shipping_total($order->id, $product);
             $shipping = $shipping_costs['shipping_amount'];
             $shipping_tax = $shipping_costs['shipping_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;
         }
         $shipping_given += $give_shipping ? $shipping : 0;
         $tax_given += $give_tax ? $total_tax : 0;
         return array('shipping_subtotal' => $shipping_given, 'tax_subtotal' => $tax_given);
     }
     return array('shipping_subtotal' => 0, 'tax_subtotal' => 0);
 }
 /**
  * Process PayPal masspay 
  */
 public function do_paypal_masspay()
 {
     global $WCMp;
     $commissions = $this->get_query_commission();
     $commission_data = $commission_totals = $commissions_data = array();
     if ($commissions) {
         $transaction_data = array();
         foreach ($commissions as $commission) {
             $WCMp_Commission = new WCMp_Commission();
             $commission_data = $WCMp_Commission->get_commission($commission->ID);
             $commission_order_id = get_post_meta($commission->ID, '_commission_order_id', true);
             $vendor_shipping = get_post_meta($commission->ID, '_shipping', true);
             $vendor_tax = get_post_meta($commission->ID, '_tax', true);
             $order = new WC_Order($commission_order_id);
             $vendor = get_wcmp_vendor_by_term($commission_data->vendor->term_id);
             $payment_type = get_user_meta($vendor->id, '_vendor_payment_mode', true);
             if ($payment_type == 'direct_bank') {
                 continue;
             }
             $due_vendor = $vendor->wcmp_get_vendor_part_from_order($order, $vendor->term_id);
             if (!$vendor_shipping) {
                 $vendor_shipping = $due_vendor['shipping'];
             }
             if (!$vendor_tax) {
                 $vendor_tax = $due_vendor['tax'];
             }
             $vendor_due = 0;
             $vendor_due = (double) $commission_data->amount + (double) $vendor_shipping + (double) $vendor_tax;
             //check unpaid commission threshold
             $total_vendor_due = $vendor->wcmp_vendor_get_total_amount_due();
             $get_vendor_thresold = 0;
             if (isset($WCMp->vendor_caps->payment_cap['commission_threshold'])) {
                 $get_vendor_thresold = (double) $WCMp->vendor_caps->payment_cap['commission_threshold'];
             }
             if ($get_vendor_thresold > $total_vendor_due) {
                 continue;
             }
             if (array_key_exists($commission_data->vendor->term_id, $transaction_data)) {
                 $commission_totals[$commission_data->vendor->term_id]['amount'] += apply_filters('paypal_masspay_amount', $vendor_due, $commission_order_id, $commission_data->vendor->term_id);
             } else {
                 $commission_totals[$commission_data->vendor->term_id]['amount'] = apply_filters('paypal_masspay_amount', $vendor_due, $commission_order_id, $commission_data->vendor->term_id);
             }
             $transaction_data[$commission_data->vendor->term_id]['commission_detail'][$commission->ID] = $commission_order_id;
             $transaction_data[$commission_data->vendor->term_id]['amount'] = $commission_totals[$commission_data->vendor->term_id]['amount'];
         }
         // Set info for all payouts
         $currency = get_woocommerce_currency();
         $payout_note = sprintf(__('Total commissions earned from %1$s as at %2$s on %3$s', $WCMp->text_domain), get_bloginfo('name'), date('H:i:s'), date('d-m-Y'));
         $commissions_data = array();
         foreach ($commission_totals as $vendor_id => $total) {
             if (!isset($total['amount'])) {
                 $total['amount'] = 0;
             }
             if (isset($total['transaction_fee'])) {
                 $total_payable = $total['amount'] + $total['transaction_fee'];
             } else {
                 $total_payable = $total['amount'];
             }
             // Get vendor data
             $vendor = get_wcmp_vendor_by_term($vendor_id);
             $vendor_paypal_email = get_user_meta($vendor->id, '_vendor_paypal_email', true);
             // Set vendor recipient field
             if (isset($vendor_paypal_email) && strlen($vendor_paypal_email) > 0) {
                 $recipient = $vendor_paypal_email;
                 $commissions_data[] = array('recipient' => $recipient, 'total' => $total_payable, 'currency' => $currency, 'vendor_id' => $vendor_id, 'payout_note' => $payout_note);
             }
         }
         $result = $this->call_masspay_api($commissions_data);
         if ($result) {
             // create a new transaction by vendor
             $WCMp->transaction->insert_new_transaction($transaction_data, 'wcmp_completed', 'paypal_masspay', $result);
         }
     }
 }
/**
 * The Template for displaying products in a product category. Simply includes the archive template.
 *
 * Override this template by copying it to yourtheme/dc-product-vendor/taxonomy-dc_vendor_shop.php
 *
 * @author 		Dualcube
 * @package 	WCMp/Templates
 * @version   2.2.0
 */
global $WCMp;
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
// Get vendor ID
$vendor = get_wcmp_vendor_by_term(get_queried_object()->term_id);
$is_block = get_user_meta($vendor->id, '_vendor_turn_off', true);
if ($is_block) {
    get_header('shop');
    ?>
	<?php 
    /**
     * woocommerce_before_main_content hook
     *
     * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
     * @hooked woocommerce_breadcrumb - 20
     */
    do_action('woocommerce_before_main_content');
    ?>

		<?php 
Example #16
0
 /**
  * Save vendor related data
  *
  * @return void
  */
 function process_vendor_data($post_id)
 {
     $post = get_post($post_id);
     if ($post->post_type == 'product') {
         if (isset($_POST['commision'])) {
             update_post_meta($post_id, '_commission_per_product', $_POST['commision']);
         }
         if (isset($_POST['commission_percentage'])) {
             update_post_meta($post_id, '_commission_percentage_per_product', $_POST['commission_percentage']);
         }
         if (isset($_POST['fixed_with_percentage_qty'])) {
             update_post_meta($post_id, '_commission_fixed_with_percentage_qty', $_POST['fixed_with_percentage_qty']);
         }
         if (isset($_POST['fixed_with_percentage'])) {
             update_post_meta($post_id, '_commission_fixed_with_percentage', $_POST['fixed_with_percentage']);
         }
         if (isset($_POST['choose_vendor']) && !empty($_POST['choose_vendor'])) {
             $term = get_term($_POST['choose_vendor'], 'dc_vendor_shop');
             if ($term) {
                 wp_delete_object_term_relationships($post_id, 'dc_vendor_shop');
                 wp_set_post_terms($post_id, $term->slug, 'dc_vendor_shop', true);
             }
             $vendor = get_wcmp_vendor_by_term($_POST['choose_vendor']);
             if (!wp_is_post_revision($post_id)) {
                 // unhook this function so it doesn't loop infinitely
                 remove_action('save_post', array($this, 'process_vendor_data'));
                 // update the post, which calls save_post again
                 wp_update_post(array('ID' => $post_id, 'post_author' => $vendor->id));
                 // re-hook this function
                 add_action('save_post', array($this, 'process_vendor_data'));
             }
         }
         if (isset($_POST['variable_post_id']) && !empty($_POST['variable_post_id'])) {
             foreach ($_POST['variable_post_id'] as $post_key => $value) {
                 if (isset($_POST['variable_product_vendors_commission'][$post_key])) {
                     $commission = $_POST['variable_product_vendors_commission'][$post_key];
                     update_post_meta($value, '_product_vendors_commission', $commission);
                 }
                 if (isset($_POST['variable_product_vendors_commission_percentage'][$post_key])) {
                     $commission = $_POST['variable_product_vendors_commission_percentage'][$post_key];
                     update_post_meta($value, '_product_vendors_commission_percentage', $commission);
                 }
                 if (isset($_POST['variable_product_vendors_commission_fixed_per_trans'][$post_key])) {
                     $commission = $_POST['variable_product_vendors_commission_fixed_per_trans'][$post_key];
                     update_post_meta($value, '_product_vendors_commission_fixed_per_trans', $commission);
                 }
                 if (isset($_POST['variable_product_vendors_commission_fixed_per_qty'][$post_key])) {
                     $commission = $_POST['variable_product_vendors_commission_fixed_per_qty'][$post_key];
                     update_post_meta($value, '_product_vendors_commission_fixed_per_qty', $commission);
                 }
                 if (isset($_POST['dc_variable_shipping_class'][$post_key])) {
                     $_POST['dc_variable_shipping_class'][$post_key] = !empty($_POST['dc_variable_shipping_class'][$post_key]) ? (int) $_POST['dc_variable_shipping_class'][$post_key] : '';
                     $array = wp_set_object_terms($value, $_POST['dc_variable_shipping_class'][$post_key], 'product_shipping_class');
                     unset($_POST['dc_variable_shipping_class'][$post_key]);
                 }
             }
         }
     }
 }
 /**
  * Get commission details
  * @param  int $commission_id Commission ID
  * @return obj                Commission object
  */
 function get_commission($commission_id = 0)
 {
     $commission = false;
     if ($commission_id > 0) {
         // Get post data
         $commission = get_post($commission_id);
         // Get meta data
         $commission->product = get_post_meta($commission_id, '_commission_product', true);
         $commission->vendor = get_wcmp_vendor_by_term(get_post_meta($commission_id, '_commission_vendor', true));
         $commission->amount = get_post_meta($commission_id, '_commission_amount', true);
         $commission->paid_status = get_post_meta($commission_id, '_paid_status', true);
     }
     return $commission;
 }
Example #18
0
 /**
  * Add 'woocommerce' class to body tag for vendor pages
  *
  * @param  arr $classes Existing classes
  * @return arr          Modified classes
  */
 public function set_product_archive_class($classes)
 {
     if (is_tax('dc_vendor_shop')) {
         // Add generic classes
         $classes[] = 'woocommerce';
         $classes[] = 'product-vendor';
         // Get vendor ID
         $vendor_id = get_queried_object()->term_id;
         // Get vendor info
         $vendor = get_wcmp_vendor_by_term($vendor_id);
         // Add vendor slug as class
         if ('' != $vendor->slug) {
             $classes[] = $vendor->slug;
         }
     }
     return $classes;
 }
Example #19
0
 /**
  * Get vendors for product
  * @param  int $product_id Product ID
  * @return arr             Array of product vendors
  */
 function get_wcmp_product_vendors($product_id = 0)
 {
     global $WCMp;
     $vendor_data = false;
     if ($product_id > 0) {
         $vendors_data = wp_get_post_terms($product_id, $WCMp->taxonomy->taxonomy_name);
         foreach ($vendors_data as $vendor) {
             $vendor_obj = get_wcmp_vendor_by_term($vendor->term_id);
             if ($vendor_obj) {
                 $vendor_data = $vendor_obj;
             }
         }
         if (!$vendor_data) {
             $product_obj = get_post($product_id);
             $author_id = $product_obj->post_author;
             if ($author_id) {
                 $vendor_data = get_wcmp_vendor($author_id);
             }
         }
     }
     return $vendor_data;
 }