/**
  * validate vendor coupon
  *
  * @param boolean $true
  * @return abject $coupon
  */
 public function woocommerce_coupon_is_valid($true, $coupon)
 {
     $current_coupon = get_post($coupon->id);
     if (is_user_wcmp_vendor($current_coupon->post_author)) {
         if ($coupon->is_type(array('fixed_product', 'percent_product'))) {
             $is_coupon_valid = false;
             if (!WC()->cart->is_empty()) {
                 foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
                     if (isset($cart_item['product_id'])) {
                         $vendor_product = get_wcmp_product_vendors($cart_item['product_id']);
                         if ($vendor_product) {
                             if ($vendor_product->id == $current_coupon->post_author) {
                                 $is_coupon_valid = true;
                             }
                         }
                     }
                 }
                 if (!$is_coupon_valid) {
                     $true = false;
                 }
             }
         }
     }
     return $true;
 }
 /**
  * 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;
         }
     }
 }
 public function wcmp_vendor_messages_customer_support($order, $sent_to_admin = false, $plain_text = false)
 {
     global $WCMp;
     $WCMp->load_class('template');
     $WCMp->template = new WCMp_Template();
     $items = $order->get_items('line_item');
     $vendor_array = array();
     $author_id = '';
     $capability_settings = get_option('wcmp_capabilities_settings_name');
     $customer_support_details_settings = get_option('wcmp_general_customer_support_details_settings_name');
     $is_csd_by_admin = '';
     foreach ($items as $item_id => $item) {
         $product_id = $order->get_item_meta($item_id, '_product_id', true);
         if ($product_id) {
             $author_id = $order->get_item_meta($item_id, '_vendor_id', true);
             if (empty($author_id)) {
                 $product_vendors = get_wcmp_product_vendors($product_id);
                 if (isset($product_vendors) && !empty($product_vendors)) {
                     $author_id = $product_vendors->id;
                 } else {
                     $author_id = get_post_field('post_author', $product_id);
                 }
             }
             if (isset($vendor_array[$author_id])) {
                 $vendor_array[$author_id] = $vendor_array[$author_id] . ',' . $item['name'];
             } else {
                 $vendor_array[$author_id] = $item['name'];
             }
         }
     }
     if ($plain_text) {
     } else {
         if (isset($capability_settings['can_vendor_add_message_on_email_and_thankyou_page'])) {
             $WCMp->template->get_template('vendor_message_to_buyer.php', array('vendor_array' => $vendor_array, 'capability_settings' => $capability_settings, 'customer_support_details_settings' => $customer_support_details_settings));
         } elseif (isset($customer_support_details_settings['is_customer_support_details'])) {
             $WCMp->template->get_template('customer_support_details_to_buyer.php', array('vendor_array' => $vendor_array, 'capability_settings' => $capability_settings, 'customer_support_details_settings' => $customer_support_details_settings));
         }
     }
 }
Exemple #5
0
 * @package 	dc-product-vendor/Templates
 * @version   2.2.0
 */
global $product, $WCMp;
$product_settings = get_option('wcmp_product_settings_name');
$product_level_policies_on = isset($product_settings['product_level_policies_on']) ? $product_settings['product_level_policies_on'] : '';
$policies_can_override_by_vendor = isset($product_settings['policies_can_override_by_vendor']) ? $product_settings['policies_can_override_by_vendor'] : '';
$cancellation_policy = isset($product_settings['cancellation_policy']) ? $product_settings['cancellation_policy'] : '';
$refund_policy = isset($product_settings['refund_policy']) ? $product_settings['refund_policy'] : '';
$shipping_policy = isset($product_settings['shipping_policy']) ? $product_settings['shipping_policy'] : '';
$cancellation_policy_label = isset($product_settings['cancellation_policy_label']) ? $product_settings['cancellation_policy_label'] : __('Cancellation/Return/Exchange Policy', $WCMp->text_domain);
$refund_policy_label = isset($product_settings['refund_policy_label']) ? $product_settings['refund_policy_label'] : __('Refund Policy', $WCMp->text_domain);
$shipping_policy_label = isset($product_settings['shipping_policy_label']) ? $product_settings['shipping_policy_label'] : __('Shipping Policy', $WCMp->text_domain);
$product_id = $product->id;
if ($policies_can_override_by_vendor != '') {
    $product_vendors = get_wcmp_product_vendors($product_id);
    if ($product_vendors) {
        $author_id = $product_vendors->id;
    } else {
        $author_id = get_post_field('post_author', $product_id);
    }
    $cancellation_policy_vendor = get_user_meta($author_id, '_vendor_cancellation_policy', true);
    $refund_policy_vendor = get_user_meta($author_id, '_vendor_refund_policy', true);
    $shipping_policy_vendor = get_user_meta($author_id, '_vendor_shipping_policy', true);
    if (!empty($cancellation_policy_vendor)) {
        $cancellation_policy = $cancellation_policy_vendor;
    }
    if (!empty($refund_policy_vendor)) {
        $refund_policy = $refund_policy_vendor;
    }
    if (!empty($shipping_policy_vendor)) {
Exemple #6
0
 /**
  * On activation, include the installer and run it.
  *
  * @access public
  * @return void
  */
 function wcmp_plugins_loaded()
 {
     global $WCMp, $wpdb;
     //delete_option('dc_product_vendor_plugin_db_version');
     $previous_plugin_version = get_option('dc_product_vendor_plugin_db_version');
     if (!$previous_plugin_version || $previous_plugin_version < $WCMp->version) {
         $prev_general = get_option('dc_general_settings_name');
         $prev_product = get_option('dc_product_settings_name');
         $prev_capability = get_option('dc_capabilities_settings_name');
         $prev_pages = get_option('dc_pages_settings_name');
         $prev_payment = get_option('dc_payment_settings_name');
         $new_general = $new_product = $new_capability = $new_pages = $new_payment = $new_frontend = array();
         $new_payment = $prev_payment;
         if (!empty($prev_general)) {
             if (isset($prev_general['enable_registration'])) {
                 $new_general['enable_registration'] = 'Enable';
             }
             if (isset($prev_general['approve_vendor_manually'])) {
                 $new_general['approve_vendor_manually'] = 'Enable';
             }
             if (isset($prev_general['notify_configure_vendor_store'])) {
                 $new_general['notify_configure_vendor_store'] = $prev_general['notify_configure_vendor_store'];
             }
             if (isset($prev_general['default_commission'])) {
                 $new_payment['default_commission'] = $prev_general['default_commission'];
             }
             if (isset($prev_general['commission_type'])) {
                 $new_payment['commission_type'] = $prev_general['commission_type'];
             }
             if (isset($prev_general['commission_include_coupon'])) {
                 $new_payment['commission_include_coupon'] = $prev_general['commission_include_coupon'];
             }
             if (isset($prev_general['sold_by_catalog'])) {
                 $new_frontend['sold_by_catalog'] = $prev_general['sold_by_catalog'];
             }
             if (isset($prev_general['catalog_colorpicker'])) {
                 $new_frontend['catalog_colorpicker'] = $prev_general['catalog_colorpicker'];
             }
             if (isset($prev_general['catalog_hover_colorpicker'])) {
                 $new_frontend['catalog_hover_colorpicker'] = $prev_general['catalog_hover_colorpicker'];
             }
             if (isset($prev_general['sold_by_cart_and_checkout'])) {
                 $new_frontend['sold_by_cart_and_checkout'] = $prev_general['sold_by_cart_and_checkout'];
             }
             if (isset($prev_general['sold_by_text'])) {
                 $new_frontend['sold_by_text'] = $prev_general['sold_by_text'];
             }
             if (isset($prev_general['block_vendor_desc'])) {
                 $new_frontend['block_vendor_desc'] = $prev_general['block_vendor_desc'];
             }
         }
         if (!empty($prev_capability)) {
             $new_capability = $prev_capability;
             if (isset($new_capability['give_tax'])) {
                 $new_payment['give_tax'] = $new_capability['give_tax'];
                 unset($new_capability['give_tax']);
             }
             if (isset($new_capability['give_shipping'])) {
                 $new_payment['give_shipping'] = $new_capability['give_shipping'];
                 unset($new_capability['give_shipping']);
             }
         }
         if (!empty($prev_product)) {
             update_option('wcmp_product_settings_name', $prev_product);
         }
         if (!empty($prev_pages)) {
             update_option('wcmp_pages_settings_name', $prev_pages);
         }
         if (!empty($new_general)) {
             update_option('wcmp_general_settings_name', $new_general);
         }
         if (!empty($new_capability)) {
             update_option('wcmp_capabilities_settings_name', $new_capability);
         }
         if (!empty($new_payment)) {
             update_option('wcmp_payment_settings_name', $new_payment);
         }
         if (!empty($new_frontend)) {
             update_option('wcmp_frontend_settings_name', $new_frontend);
         }
         delete_option('dc_general_settings_name');
         delete_option('dc_product_settings_name');
         delete_option('dc_capabilities_settings_name');
         delete_option('dc_payment_settings_name');
         delete_option('dc_pages_settings_name');
         $vendors = get_wcmp_vendors();
         if (!empty($vendors)) {
             foreach ($vendors as $vendor) {
                 $vendorusers = new WP_User($vendor->id);
                 $vendorusers->remove_cap('manage_woocommerce');
                 $vendor_products = $vendor->get_products();
                 if (!empty($vendor_products)) {
                     foreach ($vendor_products as $vendor_product) {
                         wp_update_post(array('ID' => $vendor_product->ID, 'post_author' => $vendor->id));
                         $product_obj = wc_get_product($vendor_product->ID);
                         if ($product_obj->is_type('variable')) {
                             $childrens = $product_obj->get_children();
                             foreach ($childrens as $child_id) {
                                 wp_update_post(array('ID' => $child_id, 'post_author' => $vendor->id));
                             }
                         }
                     }
                 }
             }
         }
         $vendor_role = get_role('dc_vendor');
         $vendor_role->remove_cap('manage_woocommerce');
         $wcmp_pages = get_option('wcmp_pages_settings_name');
         $page_slug = 'wcmp_withdrawal_request';
         $page_found = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_found) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Withdrawal Request Status', $WCMp->text_domain), 'post_content' => '[transaction_thankyou]', 'comment_status' => 'closed');
             $transaction_withdrawal_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_transaction_widthdrawal_page_id', $transaction_withdrawal_page_id);
             $wcmp_pages['vendor_transaction_thankyou'] = $transaction_withdrawal_page_id;
         }
         $page_slug = 'wcmp_transaction_details';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Transaction Details', $WCMp->text_domain), 'post_content' => '[transaction_details]', 'comment_status' => 'closed');
             $transaction_details_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_transaction_details_page_id', $transaction_details_page_id);
             $wcmp_pages['vendor_transaction_detail'] = $transaction_details_page_id;
         }
         $page_slug = 'wcmp_vendor_policies';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Policies', $WCMp->text_domain), 'post_content' => '[vendor_policies]', 'comment_status' => 'closed');
             $policy_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_policies_page_id', $policy_page_id);
             $wcmp_pages['vendor_policies'] = $policy_page_id;
         }
         $page_slug = 'wcmp_vendor_billing';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Billing', $WCMp->text_domain), 'post_content' => '[vendor_billing]', 'comment_status' => 'closed');
             $vendor_billing_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_billing_page_id', $vendor_billing_page_id);
             $wcmp_pages['vendor_billing'] = $vendor_billing_page_id;
         }
         $page_slug = 'wcmp_vendor_shipping';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Shipping', $WCMp->text_domain), 'post_content' => '[vendor_shipping_settings]', 'comment_status' => 'closed');
             $vendor_shipping_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_shipping_page_id', $vendor_shipping_page_id);
             $wcmp_pages['vendor_shipping'] = $vendor_shipping_page_id;
         }
         $page_slug = 'wcmp_vendor_report';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Report', $WCMp->text_domain), 'post_content' => '[vendor_report]', 'comment_status' => 'closed');
             $vendor_report_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_report_page_id', $vendor_report_page_id);
             $wcmp_pages['vendor_report'] = $vendor_report_page_id;
         }
         $page_slug = 'wcmp_vendor_widthdrawals';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Widthdrawals', $WCMp->text_domain), 'post_content' => '[vendor_widthdrawals]', 'comment_status' => 'closed');
             $vendor_widthdrawals_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_widthdrawals_page_id', $vendor_widthdrawals_page_id);
             $wcmp_pages['vendor_widthdrawals'] = $vendor_widthdrawals_page_id;
         }
         $page_slug = 'wcmp_vendor_university';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '{$page_slug}' LIMIT 1;");
         if (!$page_foundd) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor University', $WCMp->text_domain), 'post_content' => '[vendor_university]', 'comment_status' => 'closed');
             $vendor_university_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_university_page_id', $vendor_university_page_id);
             $wcmp_pages['vendor_university'] = $vendor_university_page_id;
         }
         $page_slug = 'wcmp_vendor_announcements';
         $page_foundd = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = 'wcmp_vendor_messages' LIMIT 1;");
         $page_foundd2 = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = 'wcmp_vendor_announcements' LIMIT 1;");
         if (!$page_foundd && !$page_foundd2) {
             $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $page_slug, 'post_title' => __('Vendor Announcements', $WCMp->text_domain), 'post_content' => '[vendor_announcements]', 'comment_status' => 'closed');
             $vendor_announcements_page_id = wp_insert_post($page_data);
             update_option('wcmp_product_vendor_announcements_page_id', $vendor_announcements_page_id);
             $wcmp_pages['vendor_announcements'] = $vendor_announcements_page_id;
         }
         if ($page_foundd && !$page_foundd2) {
             wp_update_post(array('ID' => $wcmp_pages['vendor_messages'], 'post_content' => '[vendor_announcements]', 'post_name' => 'vendor_announcements', 'post_title' => 'Vendor Announcements'));
             $wcmp_pages['vendor_announcements'] = $wcmp_pages['vendor_messages'];
             unset($wcmp_pages['vendor_messages']);
         }
         wp_update_post(array('ID' => $wcmp_pages['vendor_dashboard'], 'post_content' => '[vendor_dashboard]'));
         wp_update_post(array('ID' => $wcmp_pages['view_order'], 'post_content' => '[vendor_orders]'));
         update_option('wcmp_pages_settings_name', $wcmp_pages);
         if (!empty($wpdb->charset)) {
             $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
         }
         if (!empty($wpdb->collate)) {
             $charset_collate .= " COLLATE {$wpdb->collate}";
         }
         $migs = array();
         // Create course_purchase table
         $migs[] = "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "wcmp_vendor_orders` (\n\t\t\t\t`ID` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`order_id` bigint(20) NOT NULL,\n\t\t\t\t`commission_id` bigint(20) NOT NULL,\n\t\t\t\t`vendor_id` bigint(20) NOT NULL,\n\t\t\t\t`shipping_status` varchar(255) NOT NULL,\n\t\t\t\t`order_item_id` bigint(20) NOT NULL,\n\t\t\t\t`product_id` bigint(20) NOT NULL,\n\t\t\t\t`commission_amount` varchar(255) NOT NULL,\n\t\t\t\t`shipping` varchar(255) NOT NULL,\n\t\t\t\t`tax` varchar(255) NOT NULL,\n\t\t\t\t`is_trashed` varchar(10) NOT NULL,\t\t\t\t\n\t\t\t\t`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\t\t\t\t\n\t\t\t\tPRIMARY KEY (`ID`),\n\t\t\t\tCONSTRAINT vendor_orders UNIQUE (order_id, vendor_id, commission_id, product_id)\n\t\t\t){$charset_collate};";
         $needed_migration = count($migs);
         for ($i = 0; $i < $needed_migration; $i++) {
             $mig = $migs[$i];
             $wpdb->query($mig);
         }
         $WCMp_Calculate_Commission_obj = new WCMp_Calculate_Commission();
         $vendors = get_wcmp_vendors();
         if (!empty($vendors)) {
             $vendor_orders_array = array();
             foreach ($vendors as $vendor) {
                 $vendor_orders = $vendor->get_orders();
                 if (!empty($vendor_orders)) {
                     foreach ($vendor_orders as $commission_id => $order_id) {
                         $vendor_shipping_array = get_post_meta($order_id, 'dc_pv_shipped', true);
                         $order = new WC_Order($order_id);
                         $commission_array = array();
                         $mark_ship = false;
                         $items = $order->get_items('line_item');
                         foreach ($items as $order_item_id => $item) {
                             $comm_pro_id = $product_id = $order->get_item_meta($order_item_id, '_product_id', true);
                             $variation_id = $order->get_item_meta($order_item_id, '_variation_id', true);
                             if ($variation_id) {
                                 $comm_pro_id = $variation_id;
                             }
                             if ($product_id) {
                                 $product_vendors = get_wcmp_product_vendors($product_id);
                                 if ($product_vendors) {
                                     if (isset($product_vendors->id)) {
                                         if (isset($vendor_shipping_array) && !empty($vendor_shipping_array)) {
                                             if (in_array($product_vendors->id, $vendor_shipping_array)) {
                                                 $mark_ship = true;
                                             } else {
                                                 $mark_ship = 0;
                                             }
                                         } else {
                                             $mark_ship = 0;
                                         }
                                         $item_commission = $WCMp_Calculate_Commission_obj->get_item_commission($comm_pro_id, $comm_pro_id, $item, $order_id, $order_item_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', $order_item_id, '_line_tax', true);
                                         $commission_vendor_term_id = get_post_meta($commission_id, '_commission_vendor', true);
                                         $vendor_term_id = get_user_meta($product_vendors->id, '_vendor_term_id', true);
                                         if ($commission_vendor_term_id == $vendor_term_id) {
                                             $vendor_orders_array[] = array($order_id, $commission_id, $product_vendors->id, $mark_ship, $order_item_id, $comm_pro_id, $order->order_date, $item_commission, $item_shipping, $item_tax);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!empty($vendor_orders_array)) {
                 usort($vendor_orders_array, function ($a, $b) {
                     return $a[0] - $b[0];
                 });
                 if (!get_option('wcmp_vendor_orders_update')) {
                     foreach ($vendor_orders_array as $vendor_orders) {
                         $insert_query = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}wcmp_vendor_orders` ( order_id, commission_id, vendor_id, shipping_status, order_item_id, product_id, created, commission_amount, shipping, tax )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t ( %d, %d, %d, %s, %d, %d, %s, %s, %s, %s )", $vendor_orders[0], $vendor_orders[1], $vendor_orders[2], $vendor_orders[3], $vendor_orders[4], $vendor_orders[5], $vendor_orders[6], $vendor_orders[7], $vendor_orders[8], $vendor_orders[9]));
                     }
                 }
                 update_option('wcmp_vendor_orders_update', 1);
             }
         }
         update_option('dc_product_vendor_plugin_db_version', $WCMp->version);
     }
 }
Exemple #7
0
 /**
  * get vendor commission by date
  *
  * @access public
  * @param mixed $vars
  * @return array
  */
 public function vendor_sales_stat_overview($vendor, $start_date = false, $end_date = false)
 {
     global $WCMp;
     $total_sales = 0;
     $total_vendor_earnings = 0;
     $total_order_count = 0;
     $total_purchased_products = 0;
     $total_coupon_used = 0;
     $total_coupon_discuont_value = 0;
     $total_earnings = 0;
     $total_customers = array();
     $vendor = get_wcmp_vendor(get_current_user_id());
     for ($date = strtotime($start_date); $date <= strtotime('+1 day', strtotime($end_date)); $date = strtotime('+1 day', $date)) {
         $year = date('Y', $date);
         $month = date('n', $date);
         $day = date('j', $date);
         $line_total = $sales = $comm_amount = $vendor_earnings = $earnings = 0;
         $args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed'), 'meta_query' => array(array('key' => '_commissions_processed', 'value' => 'yes', 'compare' => '=')), 'date_query' => array(array('year' => $year, 'month' => $month, 'day' => $day)));
         $qry = new WP_Query($args);
         $orders = apply_filters('wcmp_filter_orders_report_overview', $qry->get_posts(), $vendor->id);
         if (!empty($orders)) {
             foreach ($orders as $order_obj) {
                 $order = new WC_Order($order_obj->ID);
                 $items = $order->get_items('line_item');
                 $commission_array = array();
                 foreach ($items as $item_id => $item) {
                     $comm_pro_id = $product_id = $order->get_item_meta($item_id, '_product_id', true);
                     $line_total = $order->get_item_meta($item_id, '_line_total', true);
                     $variation_id = $order->get_item_meta($item_id, '_variation_id', true);
                     if ($variation_id) {
                         $comm_pro_id = $variation_id;
                     }
                     if ($product_id && $line_total) {
                         $product_vendors = get_wcmp_product_vendors($product_id);
                         if ($product_vendors) {
                             $sales += $line_total;
                             $total_sales += $line_total;
                             $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($product_vendors->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_obj->ID), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($comm_pro_id), 'compare' => 'LIKE')));
                             $commissions = get_posts($args);
                             $comm_amount = 0;
                             if (!empty($commissions)) {
                                 foreach ($commissions as $commission) {
                                     if (in_array($commission->ID, $commission_array)) {
                                         continue;
                                     }
                                     $comm_amount += (double) get_post_meta($commission->ID, '_commission_amount', true);
                                     $commission_array[] = $commission->ID;
                                 }
                             }
                             $vendor_earnings += $comm_amount;
                             $total_vendor_earnings += $comm_amount;
                             $earnings += $line_total - $comm_amount;
                             $total_earnings += $line_total - $comm_amount;
                             $total_purchased_products++;
                         }
                     }
                 }
                 //coupons count
                 $coupon_used = array();
                 $coupons = $order->get_items('coupon');
                 foreach ($coupons as $coupon_item_id => $item) {
                     $coupon = new WC_Coupon(trim($item['name']));
                     $coupon_post = get_post($coupon->id);
                     $author_id = $coupon_post->post_author;
                     if ($vendor->id == $author_id) {
                         $total_coupon_used++;
                         $total_coupon_discuont_value += (double) wc_add_order_item_meta($coupon_item_id, 'discount_amount', true);
                     }
                 }
                 ++$total_order_count;
                 //user count
                 if ($order->customer_user != 0 && $order->customer_user != 1) {
                     array_push($total_customers, $order->customer_user);
                 }
             }
         }
     }
     return array('total_order_count' => $total_order_count, 'total_vendor_sales' => $total_sales, 'total_vendor_earning' => $total_vendor_earnings, 'total_coupon_discuont_value' => $total_coupon_discuont_value, 'total_coupon_used' => $total_coupon_used, 'total_customers' => array_unique($total_customers), 'total_purchased_products' => $total_purchased_products);
 }
Exemple #8
0
 /**
  * Report Abuse Vendor via AJAX
  *
  * @return void
  */
 function send_report_abuse()
 {
     global $WCMp;
     $check = false;
     $name = sanitize_text_field($_POST['name']);
     $from_email = sanitize_email($_POST['email']);
     $user_message = sanitize_text_field($_POST['msg']);
     $product_id = sanitize_text_field($_POST['product_id']);
     $check = !empty($name) && !empty($from_email) && !empty($user_message);
     if ($check) {
         $product = get_post(absint($product_id));
         $vendor = get_wcmp_product_vendors($product_id);
         $subject = __('Report an abuse for product', $WCMp->text_domain) . get_the_title($product_id);
         $to = sanitize_email(get_option('admin_email'));
         $from_email = sanitize_email($from_email);
         $headers = "From: {$name} <{$from_email}>" . "\r\n";
         $message = sprintf(__("User %s (%s) is reporting an abuse on the following product: \n", $WCMp->text_domain), $name, $from_email);
         $message .= sprintf(__("Product details: %s (ID: #%s) \n", $WCMp->text_domain), $product->post_title, $product->ID);
         $message .= sprintf(__("Vendor shop: %s \n", $WCMp->text_domain), $vendor->user_data->display_name);
         $message .= sprintf(__("Message: %s\n", $WCMp->text_domain), $user_message);
         $message .= "\n\n\n";
         $message .= sprintf(__("Product page:: %s\n", $WCMp->text_domain), get_the_permalink($product->ID));
         /* === Send Mail === */
         $response = wp_mail($to, $subject, $message, $headers);
     }
     die;
 }
 /**
  * Get assigned commission percentage
  *
  * @param  int $product_id ID of product
  * @param  int $vendor_id  ID of vendor
  * @return int             Relevent commission percentage
  */
 public function get_commission_amount($product_id = 0, $vendor_id = 0, $variation_id = 0, $item_id = '', $order = array())
 {
     global $WCMp;
     $data = array();
     if ($product_id > 0 && $vendor_id > 0) {
         $vendor_idd = $order->get_item_meta($item_id, '_vendor_id', true);
         if ($vendor_idd) {
             $vendor = get_wcmp_vendor($vendor_idd);
         } else {
             $vendor = get_wcmp_product_vendors($product_id);
         }
         if ($vendor->term_id == $vendor_id) {
             if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
                 if ($variation_id > 0) {
                     $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission_percentage', true);
                     $data['commission_fixed'] = get_post_meta($variation_id, '_product_vendors_commission_fixed_per_trans', true);
                     if (empty($data)) {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                         $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage', true);
                     }
                 } else {
                     $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                     $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage', true);
                 }
                 if (!empty($data['commission_val'])) {
                     return $data;
                     // Use product commission percentage first
                 } else {
                     $vendor_commission_percentage = 0;
                     $vendor_commission_percentage = get_user_meta($vendor->id, '_vendor_commission_percentage', true);
                     $vendor_commission_fixed_with_percentage = 0;
                     $vendor_commission_fixed_with_percentage = get_user_meta($vendor->id, '_vendor_commission_fixed_with_percentage', true);
                     if ($vendor_commission_percentage > 0) {
                         return array('commission_val' => $vendor_commission_percentage, 'commission_fixed' => $vendor_commission_fixed_with_percentage);
                         // Use vendor user commission percentage
                     } else {
                         if (isset($WCMp->vendor_caps->payment_cap['default_percentage'])) {
                             return array('commission_val' => $WCMp->vendor_caps->payment_cap['default_percentage'], 'commission_fixed' => $WCMp->vendor_caps->payment_cap['fixed_with_percentage']);
                         } else {
                             return false;
                         }
                     }
                 }
             } else {
                 if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
                     if ($variation_id > 0) {
                         $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission_percentage', true);
                         $data['commission_fixed'] = get_post_meta($variation_id, '_product_vendors_commission_fixed_per_qty', true);
                         if (!$data) {
                             $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                             $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage_qty', true);
                         }
                     } else {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                         $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage_qty', true);
                     }
                     if (!empty($data['commission_val'])) {
                         return $data;
                         // Use product commission percentage first
                     } else {
                         $vendor_commission_percentage = 0;
                         $vendor_commission_fixed_with_percentage = 0;
                         $vendor_commission_percentage = get_user_meta($vendor->id, '_vendor_commission_percentage', true);
                         $vendor_commission_fixed_with_percentage = get_user_meta($vendor->id, '_vendor_commission_fixed_with_percentage_qty', true);
                         if ($vendor_commission_percentage > 0) {
                             return array('commission_val' => $vendor_commission_percentage, 'commission_fixed' => $vendor_commission_fixed_with_percentage);
                             // Use vendor user commission percentage
                         } else {
                             if (isset($WCMp->vendor_caps->payment_cap['default_percentage'])) {
                                 return array('commission_val' => $WCMp->vendor_caps->payment_cap['default_percentage'], 'commission_fixed' => $WCMp->vendor_caps->payment_cap['fixed_with_percentage_qty']);
                             } else {
                                 return false;
                             }
                         }
                     }
                 } else {
                     if ($variation_id > 0) {
                         $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission', true);
                         if (!$data) {
                             $data['commission_val'] = get_post_meta($product_id, '_commission_per_product', true);
                         }
                     } else {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_per_product', true);
                     }
                     if (!empty($data['commission_val'])) {
                         return $data;
                         // Use product commission percentage first
                     } else {
                         $vendor_commission = get_user_meta($vendor->id, '_vendor_commission', true);
                         if ($vendor_commission) {
                             return array('commission_val' => $vendor_commission);
                             // Use vendor user commission percentage
                         } else {
                             return isset($WCMp->vendor_caps->payment_cap['default_commission']) ? array('commission_val' => $WCMp->vendor_caps->payment_cap['default_commission']) : false;
                             // Use default commission
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  * Save sold by text in database
  *
  * @param item_id, cart_item
  * @return void 
  */
 function order_item_meta_2($item_id, $cart_item)
 {
     global $WCMp;
     if ($WCMp->vendor_caps->vendor_frontend_settings('sold_by_cart_and_checkout')) {
         $general_cap = isset($this->frontend_cap['sold_by_text']) ? $this->frontend_cap['sold_by_text'] : '';
         if (!$general_cap) {
             $general_cap = 'Sold By';
         }
         $vendor = get_wcmp_product_vendors($cart_item['product_id']);
         if ($vendor) {
             woocommerce_add_order_item_meta($item_id, $general_cap, $vendor->user_data->display_name);
             woocommerce_add_order_item_meta($item_id, '_vendor_id', $vendor->id);
         }
     }
 }
 /**
  * wcmp_get_vendors_due_from_order function to get vendor due from an order.
  * @access public
  * @param order , vendor term id 
  */
 function wcmp_get_vendors_due_from_order($order_id)
 {
     $order = new WC_Order($order_id);
     $items = $order->get_items('line_item');
     $vendors_array = array();
     if ($items) {
         foreach ($items as $item_id => $item) {
             $product_id = $order->get_item_meta($item_id, '_product_id', true);
             if ($product_id) {
                 $vendor = get_wcmp_product_vendors($product_id);
                 if (!empty($vendor) && isset($vendor->term_id)) {
                     $vendors_array[$vendor->term_id] = $vendor->wcmp_get_vendor_part_from_order($order, $vendor->term_id);
                 }
             }
         }
     }
     return $vendors_array;
 }
Exemple #12
0
<?php

/**
 * The template for displaying single product page vendor tab 
 *
 * Override this template by copying it to yourtheme/dc-product-vendor/vendor_tab.php
 *
 * @author 		dualcube
 * @package 	dc-product-vendor/Templates
 * @version   2.2.0
 */
global $WCMp, $product;
$html = '';
$vendor = get_wcmp_product_vendors($product->id);
if ($vendor) {
    $html .= '<div class="product-vendor">';
    $html .= apply_filters('wcmp_before_seller_info_tab', '');
    $html .= '<h2>' . $vendor->user_data->display_name . '</h2>';
    if ('' != $vendor->description) {
        $html .= '<p>' . $vendor->description . '</p>';
    }
    $html .= '<p><a href="' . $vendor->permalink . '">' . sprintf(__('More Products from %1$s', $WCMp->text_domain), $vendor->user_data->display_name) . '</a></p>';
    $html .= apply_filters('wcmp_after_seller_info_tab', '');
    $html .= '</div>';
}
echo $html;
    /**
     * Vendor report abuse option
     */
    function add_report_abuse_link()
    {
        global $product, $WCMp;
        $is_display = false;
        $settings_is_display = $WCMp->vendor_caps->frontend_cap;
        if (isset($settings_is_display['show_report_abuse'])) {
            if ($settings_is_display['show_report_abuse'] == 'all_products') {
                $is_display = true;
            } else {
                if ($settings_is_display['show_report_abuse'] == 'only_vendor_products') {
                    if (get_wcmp_product_vendors($product->id)) {
                        $is_display = true;
                    }
                } else {
                    if ($settings_is_display['show_report_abuse'] == 'disable') {
                        $is_display = false;
                    }
                }
            }
        } else {
            $is_display = true;
        }
        $report_abuse_text = $WCMp->vendor_caps->frontend_cap;
        if (isset($report_abuse_text['report_abuse_text'])) {
            $display_text = $report_abuse_text['report_abuse_text'];
        } else {
            $display_text = __('Report Abuse', $WCMp->text_domain);
        }
        if ($is_display) {
            ?>
			<a href="#" id="report_abuse"><?php 
            echo $display_text;
            ?>
</a>
			<div id="report_abuse_form" class="simplePopup"> 
				<h3 class="wcmp-abuse-report-title"><?php 
            _e('Report an abuse for product', $WCMp->text_domain) . ' ' . the_title();
            ?>
 </h3>
				<form action="#" method="post" id="report-abuse" class="report-abuse-form">
					<table>
						<tbody>
							<tr>
								<td>
									<input type="text" class="report_abuse_name" name="report_abuse[name]" value="" style="width: 100%;" placeholder="<?php 
            _e('Name', $WCMp->text_domain);
            ?>
" required="">
								</td>
							</tr>
							<tr>
								<td>
									<input type="email" class="report_abuse_email" name="report_abuse[email]" value="" style="width: 100%;" placeholder="<?php 
            _e('Email', $WCMp->text_domain);
            ?>
" required="">
								</td>
							</tr>
							<tr>
								<td>
									<textarea name="report_abuse[message]" class="report_abuse_msg" rows="5" style="width: 100%;" placeholder="<?php 
            _e('Leave a message explaining the reasons for your abuse report', $WCMp->text_domain);
            ?>
" required=""></textarea>
								</td>
							</tr>
							<tr>
								<td>
									<input type="hidden" class="report_abuse_product_id" value="<?php 
            echo $product->id;
            ?>
">
									<input type="submit" class="submit-report-abuse submit" name="report_abuse[submit]" value="<?php 
            _e('Report', $WCMp->text_domain);
            ?>
">
								</td>
							</tr>
						</tbody>
					</table>
				</form>
			</div> 							
			<?php 
        }
    }
    /**
     * Output the report
     */
    public function output_report()
    {
        global $wpdb, $woocommerce, $WCMp;
        $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['search_product'])) {
            $is_variation = false;
            $product_id = $_POST['search_product'];
            $_product = get_product($product_id);
            if ($_product->is_type('variation')) {
                $title = $_product->get_formatted_name();
                $is_variation = true;
            } else {
                $title = $_product->get_title();
            }
        }
        if (isset($product_id)) {
            $option = '<option value="' . $product_id . '" selected="selected">' . $title . '</option>';
        } else {
            $option = '<option></option>';
        }
        $start_date = $this->start_date;
        $end_date = $this->end_date;
        $end_date = strtotime('+1 day', $end_date);
        $products = $product_ids = array();
        $vendor = false;
        $current_user_id = '';
        $current_user_id = get_current_user_id();
        $vendor = get_wcmp_vendor($current_user_id);
        if ($vendor) {
            $products = $vendor->get_products();
            foreach ($products as $product) {
                $product_ids[] = $product->ID;
            }
        } else {
            $args = array('posts_per_page' => -1, 'offset' => 0, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'product', 'post_status' => 'publish');
            $products = get_posts($args);
            foreach ($products as $product) {
                $product_ids[] = $product->ID;
            }
        }
        $total_sales = $admin_earnings = array();
        $max_total_sales = $index = 0;
        $product_report = $report_bk = array();
        if (isset($product_ids) && !empty($product_ids)) {
            foreach ($product_ids as $product_id) {
                $is_variation = false;
                $_product = array();
                $vendor = false;
                $_product = get_product($product_id);
                if ($_product->is_type('variation')) {
                    $title = $_product->get_formatted_name();
                    $is_variation = true;
                } else {
                    $title = $_product->get_title();
                }
                if (isset($product_id) && !$is_variation) {
                    $vendor = get_wcmp_product_vendors($product_id);
                } else {
                    if (isset($product_id) && $is_variation) {
                        $variation_parent = wp_get_post_parent_id($product_id);
                        $vendor = get_wcmp_product_vendors($variation_parent);
                    }
                }
                if ($vendor) {
                    $orders = array();
                    if ($_product->is_type('variable')) {
                        $get_children = $_product->get_children();
                        if (!empty($get_children)) {
                            foreach ($get_children as $child) {
                                $orders = array_merge($orders, $vendor->get_vendor_orders_by_product($vendor->term_id, $child));
                            }
                            $orders = array_unique($orders);
                        }
                    } else {
                        $orders = array_unique($vendor->get_vendor_orders_by_product($vendor->term_id, $product_id));
                    }
                }
                $order_items = array();
                $i = 0;
                if (!empty($orders)) {
                    foreach ($orders as $order_id) {
                        $order = new WC_Order($order_id);
                        $order_line_items = $order->get_items('line_item');
                        if (!empty($order_line_items)) {
                            foreach ($order_line_items as $line_item) {
                                if ($line_item['product_id'] == $product_id) {
                                    if ($_product->is_type('variation')) {
                                        $order_items_product_id = $line_item['product_id'];
                                        $order_items_variation_id = $line_item['variation_id'];
                                    } else {
                                        $order_items_product_id = $line_item['product_id'];
                                        $order_items_variation_id = $line_item['variation_id'];
                                    }
                                    $order_date_str = strtotime($order->order_date);
                                    if ($order_date_str > $start_date && $order_date_str < $end_date) {
                                        $order_items[$i] = array('order_id' => $order_id, 'product_id' => $order_items_product_id, 'variation_id' => $order_items_variation_id, 'line_total' => $line_item['line_total'], 'item_quantity' => $line_item['qty'], 'post_date' => $order->order_date, 'multiple_product' => 0);
                                        if (count($order_line_items) > 1) {
                                            $order_items[$i]['multiple_product'] = 1;
                                        }
                                        $i++;
                                    }
                                }
                            }
                        }
                    }
                }
                if (isset($order_items) && !empty($order_items)) {
                    foreach ($order_items as $item_id => $order_item) {
                        if ($order_item['line_total'] == 0 && $order_item['item_quantity'] == 0) {
                            continue;
                        }
                        if ($order_item['variation_id'] != 0) {
                            $variation_id = $order_item['variation_id'];
                            $product_id_1 = $order_item['variation_id'];
                        } else {
                            $variation_id = 0;
                            $product_id_1 = $order_item['product_id'];
                        }
                        $vendor = get_wcmp_product_vendors($product_id);
                        if (!$vendor) {
                            break;
                        }
                        $commissions = false;
                        $vendor_earnings = 0;
                        if ($order_item['multiple_product'] == 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_1), 'compare' => 'LIKE')));
                            $commissions = get_posts($args);
                            if (!empty($commissions)) {
                                foreach ($commissions as $item_id => $commission) {
                                    $vendor_earnings = $vendor_earnings + get_post_meta($commission->ID, '_commission_amount', true);
                                }
                            }
                        } else {
                            if ($order_item['multiple_product'] == 1) {
                                $vendor_obj = new WCMp_Vendor();
                                $vendor_items = $vendor_obj->get_vendor_items_from_order($order_item['order_id'], $vendor->term_id);
                                foreach ($vendor_items as $vendor_item) {
                                    if ($variation_id == 0) {
                                        if ($vendor_item['product_id'] == $product_id) {
                                            $item = $vendor_item;
                                            break;
                                        }
                                    } else {
                                        if ($vendor_item['product_id'] == $product_id && $vendor_item['variation_id'] == $variation_id) {
                                            $item = $vendor_item;
                                            break;
                                        }
                                    }
                                }
                                $commission_obj = new WCMp_Calculate_Commission();
                                $vendor_earnings = $commission_obj->get_item_commission($product_id, $variation_id, $item, $order_item['order_id'], $item_id);
                            }
                        }
                        if ($vendor_earnings <= 0) {
                            continue;
                        }
                        $total_sales[$product_id] = isset($total_sales[$product_id]) ? $total_sales[$product_id] + $order_item['line_total'] : $order_item['line_total'];
                        $vendor = get_wcmp_vendor($current_user_id);
                        if (!$vendor) {
                            $admin_earnings[$product_id] = isset($admin_earnings[$product_id]) ? $admin_earnings[$product_id] + $order_item['line_total'] - $vendor_earnings : $order_item['line_total'] - $vendor_earnings;
                        } else {
                            $admin_earnings[$product_id] = isset($admin_earnings[$product_id]) ? $admin_earnings[$product_id] + $vendor_earnings : $vendor_earnings;
                        }
                        if ($total_sales[$product_id] > $max_total_sales) {
                            $max_total_sales = $total_sales[$product_id];
                        }
                    }
                }
                if (!empty($total_sales[$product_id]) && !empty($admin_earnings[$product_id])) {
                    $product_report[$index]['product_id'] = $product_id;
                    $product_report[$index]['total_sales'] = $total_sales[$product_id];
                    $product_report[$index++]['admin_earning'] = $admin_earnings[$product_id];
                    $report_bk[$product_id]['total_sales'] = $total_sales[$product_id];
                    $report_bk[$product_id]['admin_earning'] = $admin_earnings[$product_id];
                }
            }
            $i = 0;
            $max_value = 10;
            $report_sort_arr = array();
            $total_sales_sort = $admin_earning_sort = array();
            if (!empty($product_report) && !empty($report_bk)) {
                $total_sales_sort = wp_list_pluck($product_report, 'total_sales', 'product_id');
                $admin_earning_sort = wp_list_pluck($product_report, 'admin_earning', 'product_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 $product_id => $value) {
                    if ($i++ < $max_value) {
                        $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                        $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                    }
                }
            }
            wp_localize_script('wcmp_report_js', 'wcmp_report_product', array('product_report' => $product_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));
            $report_chart = $report_html = '';
            if (sizeof($report_sort_arr) > 0) {
                foreach ($report_sort_arr as $product_id => $sales_report) {
                    $width = $sales_report['total_sales'] > 0 ? round($sales_report['total_sales']) / round($max_total_sales) * 100 : 0;
                    $width2 = $sales_report['admin_earning'] > 0 ? round($sales_report['admin_earning']) / round($max_total_sales) * 100 : 0;
                    $product = new WC_Product($product_id);
                    $product_url = admin_url('post.php?post=' . $product_id . '&action=edit');
                    $report_chart .= '<tr><th><a href="' . $product_url . '">' . $product->get_title() . '</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($width) . '%">&nbsp;</span>
							<span class="alt" style="width:' . esc_attr($width2) . '%">&nbsp;</span>
						</td></tr>';
                }
                $report_html = '
					<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>' . __("Month", $WCMp->text_domain) . '</th>
								<th colspan="2">' . __("Sales Report", $WCMp->text_domain) . '</th>
							</tr>
						</thead>
						<tbody>
							' . $report_chart . '
						</tbody>
					</table>
				';
            } else {
                $report_html = '<tr><td colspan="3">' . __('No product was sold in the given period.', $WCMp->text_domain) . '</td></tr>';
            }
        } else {
            $report_html = '<tr><td colspan="3">' . __('Your store has no products.', $WCMp->text_domain) . '</td></tr>';
        }
        include $WCMp->plugin_path . '/classes/reports/views/html-wcmp-report-by-product.php';
    }
 /**
  * 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;
     }
 }
 /**
  * get_vendor_items_from_order function get items of a order belongs to a vendor
  * @access public
  * @param order_id , vendor term id 
  * @return array with order item detail
  */
 public function get_vendor_items_from_order($order_id, $term_id)
 {
     $item_dtl = array();
     $order = new WC_Order($order_id);
     if ($order) {
         $items = $order->get_items('line_item');
         if ($items) {
             foreach ($items as $item_id => $item) {
                 $product_id = $order->get_item_meta($item_id, '_product_id', true);
                 if ($product_id) {
                     if ($term_id > 0) {
                         $product_vendors = get_wcmp_product_vendors($product_id);
                         if (!empty($product_vendors) && $product_vendors->term_id == $term_id) {
                             $item_dtl[$item_id] = $item;
                         }
                     }
                 }
             }
         }
     }
     return $item_dtl;
 }
 /**
  * Get all data needed for this report and store in the class
  */
 private function query_report_data()
 {
     $this->report_data = new stdClass();
     $start_date = $this->start_date;
     $end_date = $this->end_date;
     $chart_data_order_count = array();
     $total_order_count = 0;
     $total_earnings = 0;
     $total_sales = 0;
     $total_avg_sales = 0;
     $total_vendor_earnings = 0;
     for ($date = $start_date; $date <= strtotime('+1 day', $end_date); $date = strtotime('+1 day', $date)) {
         $year = date('Y', $date);
         $month = date('n', $date);
         $day = date('j', $date);
         $line_total = $sales = $comm_amount = $vendor_earnings = $earnings = $order_count = 0;
         $args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed'), 'meta_query' => array(array('key' => '_commissions_processed', 'value' => 'yes', 'compare' => '=')), 'date_query' => array(array('year' => $year, 'month' => $month, 'day' => $day)));
         $qry = new WP_Query($args);
         $orders = apply_filters('wcmp_filter_orders_report_overview', $qry->get_posts());
         if (!empty($orders)) {
             foreach ($orders as $order_obj) {
                 $order = new WC_Order($order_obj->ID);
                 $items = $order->get_items('line_item');
                 $commission_array = array();
                 foreach ($items as $item_id => $item) {
                     $comm_pro_id = $product_id = $order->get_item_meta($item_id, '_product_id', true);
                     $line_total = $order->get_item_meta($item_id, '_line_total', true);
                     $variation_id = $order->get_item_meta($item_id, '_variation_id', true);
                     if ($variation_id) {
                         $comm_pro_id = $variation_id;
                     }
                     if ($product_id && $line_total) {
                         $vendor_id = $order->get_item_meta($item_id, '_vendor_id', true);
                         if ($vendor_id) {
                             $product_vendors = get_wcmp_vendor($vendor_id);
                         } else {
                             $product_vendors = get_wcmp_product_vendors($product_id);
                         }
                         if ($product_vendors) {
                             $sales += $line_total;
                             $total_sales += $line_total;
                             $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($product_vendors->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_obj->ID), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($comm_pro_id), 'compare' => 'LIKE')));
                             $commissions = get_posts($args);
                             $comm_amount = 0;
                             if (!empty($commissions)) {
                                 foreach ($commissions as $commission) {
                                     if (in_array($commission->ID, $commission_array)) {
                                         continue;
                                     }
                                     $comm_amount += (double) get_post_meta($commission->ID, '_commission_amount', true);
                                     $commission_array[] = $commission->ID;
                                 }
                             }
                             $vendor_earnings += $comm_amount;
                             $total_vendor_earnings += $comm_amount;
                             $earnings += $line_total - $comm_amount;
                             $total_earnings += $line_total - $comm_amount;
                         }
                     }
                 }
                 ++$order_count;
                 ++$total_order_count;
             }
         }
         if ($order_count > 0) {
             $avg_sales = $sales / $order_count;
         } else {
             $avg_sales = 0;
         }
         $chart_data_order_count[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'count' => $order_count));
         $chart_data_sales[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'sales' => $sales));
         $chart_data_vendor_earnings[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'vendor_earnings' => $vendor_earnings));
         $chart_data_earnings[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'earnings' => $earnings));
         $chart_data_avg_sales[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'avg_sales' => $avg_sales));
     }
     $this->report_data->order_count = $chart_data_order_count;
     $this->report_data->sales = $chart_data_sales;
     $this->report_data->vendor_earnings = $chart_data_vendor_earnings;
     $this->report_data->earnings = $chart_data_earnings;
     $this->report_data->avg_sales = $chart_data_avg_sales;
     if ($total_order_count > 0) {
         $total_avg_sales = $total_sales / $total_order_count;
     } else {
         $total_avg_sales = 0;
     }
     // Total order_count
     $this->report_data->total_orders = $total_order_count;
     // Total the refunds and sales amounts. Sales subract refunds.
     $this->report_data->total_sales = wc_format_decimal($total_sales);
     // Calculate average based on net
     $this->report_data->average_sales = wc_format_decimal($total_avg_sales);
     $this->report_data->total_earned = wc_format_decimal($total_earnings);
     $this->report_data->vendor_total_earned = wc_format_decimal($total_vendor_earnings);
 }
 /**
  * WCMp Calculate shipping for order
  *
  * @support flat rate per item 
  * @param int $order_id
  * @param object $order_posted
  * @return void
  */
 function wcmp_checkout_order_processed($order_id, $order_posted)
 {
     global $wpdb, $WCMp;
     $order = new WC_Order($order_id);
     if ($order->has_shipping_method('flat_rate')) {
         $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings');
         $line_items = $order->get_items('line_item');
         if ($woocommerce_flat_rate_settings['enabled'] == 'yes') {
             if (version_compare(WC_VERSION, '2.5.0', '>=')) {
                 if ($woocommerce_flat_rate_settings['type'] == 'class') {
                     if (!empty($line_items)) {
                         foreach ($line_items as $item_id => $item) {
                             $wc_flat_rate = new WC_Shipping_Flat_Rate();
                             $product = $order->get_product_from_item($item);
                             $shipping_class = $product->get_shipping_class_id();
                             $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', '');
                             $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                             $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                             if (!$flat_shipping_per_item_val) {
                                 wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                             }
                         }
                     }
                 }
             } else {
                 if (version_compare(WC_VERSION, '2.4.0', '>')) {
                     if ($woocommerce_flat_rate_settings['type'] == 'class') {
                         if (!empty($line_items)) {
                             foreach ($line_items as $item_id => $item) {
                                 $wc_flat_rate = new WC_Shipping_Flat_Rate();
                                 $product = $order->get_product_from_item($item);
                                 $shipping_class = $product->get_shipping_class();
                                 $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', '');
                                 $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                                 $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                                 if (!$flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                                 }
                             }
                         }
                     }
                 } else {
                     $woocommerce_flat_rate_settings_cost = $woocommerce_flat_rate_settings['cost'];
                     $woocommerce_flat_rate_settings_fee = $woocommerce_flat_rate_settings['fee'];
                     $woocommerce_flat_rates = get_option('woocommerce_flat_rates');
                     if ($woocommerce_flat_rate_settings['type'] == 'item') {
                         if (!empty($line_items)) {
                             foreach ($line_items as $item_id => $item) {
                                 $fee = $cost = 0;
                                 $_product = $order->get_product_from_item($item);
                                 $shipping_class = $_product->get_shipping_class();
                                 if (isset($woocommerce_flat_rates[$shipping_class])) {
                                     $cost = $woocommerce_flat_rates[$shipping_class]['cost'];
                                     $fee = $this->get_fee($woocommerce_flat_rates[$shipping_class]['fee'], $_product->get_price());
                                 } elseif ($woocommerce_flat_rate_settings_cost !== '') {
                                     $cost = $woocommerce_flat_rate_settings_cost;
                                     $fee = $this->get_fee($woocommerce_flat_rate_settings_fee, $_product->get_price());
                                     $matched = true;
                                 }
                                 $cost_item_id = ($cost + $fee) * $item['qty'];
                                 $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                                 if (!$flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($order->has_shipping_method('international_delivery')) {
         $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings');
         $line_items = $order->get_items('line_item');
         if ($woocommerce_international_delivery_settings['enabled'] == 'yes') {
             if (version_compare(WC_VERSION, '2.5.0', '>=')) {
                 if ($woocommerce_international_delivery_settings['type'] == 'class') {
                     if (!empty($line_items)) {
                         $item_id = false;
                         foreach ($line_items as $item_id => $item) {
                             $wc_international_flat_rate = new WC_Shipping_International_Delivery();
                             $product = $order->get_product_from_item($item);
                             $shipping_class = $product->get_shipping_class_id();
                             $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', '');
                             $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                             $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true);
                             if (!$international_flat_shipping_per_item_val) {
                                 wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id);
                             }
                         }
                     }
                 }
             } else {
                 if (version_compare(WC_VERSION, '2.4.0', '>')) {
                     if ($woocommerce_international_delivery_settings['type'] == 'class') {
                         if (!empty($line_items)) {
                             $item_id = false;
                             foreach ($line_items as $item_id => $item) {
                                 $wc_international_flat_rate = new WC_Shipping_International_Delivery();
                                 $product = $order->get_product_from_item($item);
                                 $shipping_class = $product->get_shipping_class();
                                 $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', '');
                                 $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                                 $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true);
                                 if (!$international_flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $vendor_shipping_array = get_post_meta($order_id, 'dc_pv_shipped', true);
     $order = new WC_Order($order_id);
     $commission_array = array();
     $mark_ship = 0;
     $items = $order->get_items('line_item');
     foreach ($items as $order_item_id => $item) {
         $comm_pro_id = $product_id = $item['product_id'];
         $variation_id = $item['variation_id'];
         if ($variation_id) {
             $comm_pro_id = $variation_id;
         }
         if ($product_id) {
             $product_vendors = get_wcmp_product_vendors($product_id);
             if ($product_vendors) {
                 if (isset($product_vendors->id) && is_array($vendor_shipping_array)) {
                     if (in_array($product_vendors->id, $vendor_shipping_array)) {
                         $mark_ship = 1;
                     }
                 }
                 $insert_query = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}wcmp_vendor_orders` ( order_id, commission_id, vendor_id, shipping_status, order_item_id, product_id )\n\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t ( %d, %d, %d, %s, %d, %d ) ON DUPLICATE KEY UPDATE `created` = now()", $order_id, 0, $product_vendors->id, $mark_ship, $order_item_id, $comm_pro_id));
             }
         }
     }
 }
    /**
     * 	list of vendors 
     * 
     * 	@param $atts shortcode attributs 
     */
    public function wcmp_show_vendorslist($atts)
    {
        global $WCMp;
        $vendors_available = false;
        $get_all_vendors = array();
        $select_html = '';
        extract(shortcode_atts(array('orderby' => 'registered', 'order' => 'ASC'), $atts));
        $vendors = '';
        $vendor_sort_type = '';
        if (isset($_GET['vendor_sort_type'])) {
            if ($_GET['vendor_sort_type'] == 'category') {
                $vendors_ids = array();
                $vendor_sort_type = $_GET['vendor_sort_type'];
                $selected_category = $_GET['vendor_sort_category'];
                $args = array('post_type' => 'product', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $selected_category)));
                $wp_obj = new WP_Query($args);
                $sorted_products = $wp_obj->posts;
                if (isset($sorted_products) && !empty($sorted_products)) {
                    foreach ($sorted_products as $sorted_product) {
                        $vendor_obj = get_wcmp_product_vendors($sorted_product->ID);
                        if (isset($vendor_obj) && !empty($vendor_obj)) {
                            if (!in_array($vendor_obj->id, $vendors_ids)) {
                                $vendors_ids[] = $vendor_obj->id;
                                $get_all_vendors[] = new WCMp_Vendor($vendor_obj->id);
                                $vendors_available = true;
                            }
                        }
                    }
                }
            } else {
                $vendor_sort_type = $_GET['vendor_sort_type'];
                $orderby = $vendor_sort_type;
                $order = 'ASC';
            }
        }
        if (!$vendors_available) {
            $get_all_vendors = get_wcmp_vendors(array('orderby' => $orderby, 'order' => $order));
        }
        $vendors .= '<div class="vendor_list">';
        $vendors .= '<form name="vendor_sort" method="get" ><div class="vendor_sort">';
        $vendors .= '<select class="select short" id="vendor_sort_type" name="vendor_sort_type">';
        if ($vendor_sort_type) {
            if ($vendor_sort_type == 'registered') {
                $option = '<option selected value="registered">' . __("By date", $WCMp->text_domain) . '</option><option value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
            } else {
                if ($vendor_sort_type == 'name') {
                    $option = '<option value="registered">' . __("By date", $WCMp->text_domain) . '</option><option selected value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
                } else {
                    if ($vendor_sort_type == 'category') {
                        $option = '<option value="registered">' . __("By date", $WCMp->text_domain) . '</option><option value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option selected value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
                    } else {
                        $option = '<option value="registered">' . __("By date", $WCMp->text_domain) . '</option><option value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
                    }
                }
            }
        } else {
            if ($orderby == 'registered') {
                $option = '<option selected value="registered">' . __("By date", $WCMp->text_domain) . '</option><option value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
            } else {
                if ($orderby == 'name') {
                    $option = '<option  value="registered">' . __("By date", $WCMp->text_domain) . '</option><option selected value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
                } else {
                    if ($vendor_sort_type == 'category') {
                        $option = '<option value="registered">' . __("By date", $WCMp->text_domain) . '</option><option value="name">' . __("By Alphabetically", $WCMp->text_domain) . '</option><option value="category">' . __("By Category", $WCMp->text_domain) . '</option>';
                    }
                }
            }
        }
        if (isset($_GET['vendor_sort_type'])) {
            if ($_GET['vendor_sort_type'] == 'category') {
                $category_terms = get_terms('product_cat');
                $select_html = '&nbsp&nbsp&nbsp<select class="select" id="vendor_sort_category" name="vendor_sort_category">';
                foreach ($category_terms as $terms) {
                    if (isset($_GET['vendor_sort_category'])) {
                        if ($_GET['vendor_sort_category'] == $terms->term_id) {
                            $select_html .= '<option selected value="' . $terms->term_id . '">' . $terms->name . '</option>';
                        } else {
                            $select_html .= '<option value="' . $terms->term_id . '">' . $terms->name . '</option>';
                        }
                    }
                }
                $select_html .= '</select>';
            }
        }
        $vendors .= $option . '</select>' . $select_html;
        $vendors .= '&nbsp;&nbsp;&nbsp;<input type="submit" value="' . __("Sort", $WCMp->text_domain) . '" />';
        $vendors .= '</div>';
        $vendors .= '</form>';
        $get_blocked = wcmp_get_all_blocked_vendors();
        $get_block_array = array();
        if (!empty($get_blocked)) {
            foreach ($get_blocked as $get_block) {
                $get_block_array[] = (int) $get_block->id;
            }
        }
        if (isset($get_all_vendors) && !empty($get_all_vendors)) {
            foreach ($get_all_vendors as $get_vendor) {
                if (in_array($get_vendor->id, $get_block_array)) {
                    continue;
                }
                if (!$get_vendor->image) {
                    $get_vendor->image = $WCMp->plugin_url . 'assets/images/WP-stdavatar.png';
                }
                $vendors .= '<div class="sorted_vendors" style="display:inline-block; margin-right:10%;">
											 <center>
													<a href="' . $get_vendor->permalink . '"><img width="125" class="vendor_img" src="' . $get_vendor->image . '" id="vendor_image_display"></a><br />
													<a href="' . $get_vendor->permalink . '" class="button">' . $get_vendor->user_data->display_name . '</a>
													<br /><br />
											 </center>
										 </div>';
            }
            $vendors .= '</div>';
        }
        return $vendors;
    }