/** * Constructor */ function __construct() { if (!is_admin()) { return; } add_action('edit_user_profile', array($this, 'show_extra_profile_fields')); add_action('edit_user_profile_update', array($this, 'save_extra_profile_fields')); add_filter('add_menu_classes', array($this, 'show_pending_number')); // add_filter( 'get_terms', array( $this, 'get_terms_filter' ), 10, 3 ); // Displaying users by the Vendor role if (!empty($_GET['role']) && $_GET['role'] == 'vendor') { add_action('manage_users_columns', array($this, 'manage_users_columns')); add_action('manage_users_custom_column', array($this, 'custom_manage_users_column_value'), 10, 3); add_filter('manage_users_sortable_columns', array($this, 'custom_sortable')); } // Disabling non-vendor related items on the admin screens if (PV_Vendors::is_vendor(get_current_user_id())) { add_filter('woocommerce_csv_product_role', array($this, 'csv_import_suite_compatibility')); add_filter('woocommerce_csv_product_export_args', array($this, 'csv_import_suite_compatibility_export')); // Admin page lockdown remove_action('admin_init', 'woocommerce_prevent_admin_access'); add_action('admin_init', array($this, 'prevent_admin_access')); add_filter('woocommerce_prevent_admin_access', array($this, 'deny_admin_access')); // WC > Product page fixes add_action('load-edit.php', array($this, 'edit_nonvendors')); add_filter('views_edit-product', array($this, 'hide_nonvendor_links')); add_action('pre_get_posts', array($this, 'users_own_attachments')); add_action('admin_menu', array($this, 'remove_menu_page'), 99); add_action('add_meta_boxes', array($this, 'remove_meta_boxes'), 99); add_filter('product_type_selector', array($this, 'filter_product_types'), 99, 2); add_filter('product_type_options', array($this, 'filter_product_type_options'), 99); add_filter('woocommerce_duplicate_product_capability', array($this, 'add_duplicate_capability')); } }
/** * * * @param unknown $name * @param unknown $_product * * @return unknown */ function show_vendor_in_email($name, $_product) { $product = get_post($_product->id); $sold_by = PV_Vendors::is_vendor($product->post_author) ? sprintf('<a href="%s" target="_TOP">%s</a>', PV_Vendors::get_vendor_shop_page($product->post_author), PV_Vendors::get_vendor_shop_name($product->post_author)) : get_bloginfo('name'); $name .= '<small><br />' . __('Sold by', 'wc_product_vendor') . ': ' . $sold_by . '</small><br />'; return $name; }
/** * * * @param unknown $products * * @return unknown */ public function filter_products_json($products) { $vendor_products = PV_Vendors::get_vendor_products($this->vendor_id); $ids = array(); foreach ($vendor_products as $vendor_product) { $ids[$vendor_product->ID] = $vendor_product->post_title; } return array_intersect_key($products, $ids); }
public function filter_comment($commentdata, $order) { $user_id = get_current_user_id(); $commentdata['user_id'] = $user_id; $commentdata['comment_author'] = PV_Vendors::get_vendor_shop_name($user_id); $commentdata['comment_author_url'] = PV_Vendors::get_vendor_shop_page($user_id); $commentdata['comment_author_email'] = wp_get_current_user()->user_email; return $commentdata; }
/** * trigger function. * * @access public * @return void * * @param unknown $order_id */ function trigger($post_id, $post) { if (!PV_Vendors::is_vendor($post->post_author)) { return; } $this->find[] = '{product_name}'; $this->product_name = $post->post_title; $this->replace[] = $this->product_name; $this->find[] = '{vendor_name}'; $this->vendor_name = PV_Vendors::get_vendor_shop_name($post->post_author); $this->replace[] = $this->vendor_name; $this->post_id = $post_id; $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); }
/** * Set commission to 'paid' for an entire order * * * @access public * * @param mixed $order_id An array of Order IDs or an int. * @param unknown $column_ids (optional) * * @return bool. */ public function set_order_commission_paid($order_id, $column_ids = false) { global $wpdb; $table_name = $wpdb->prefix . "pv_commission"; $column = $column_ids ? 'id' : 'order_id'; if (is_array($order_id)) { $order_id = implode(',', $order_id); } $query = "SELECT sum(`total_due` + `total_shipping` + `tax`) as total, `vendor_id` FROM `{$table_name}` WHERE `status` != 'paid' AND `{$column}` IN ({$order_id}) GROUP BY `vendor_id`"; $dues = $wpdb->get_results($query); if (empty($dues)) { return false; } foreach ($dues as $due) { PV_Vendors::update_total_due($due->vendor_id, $due->total * -1); } $query = "UPDATE `{$table_name}` SET `status` = 'paid' WHERE order_id IN ({$order_id})"; $result = $wpdb->query($query); return $result; }
public function page_title($page_title = "") { $vendor_shop = urldecode(get_query_var('vendor_shop')); $vendor_id = PV_Vendors::get_vendor_id($vendor_shop); return $vendor_id ? PV_Vendors::get_vendor_shop_name($vendor_id) : $page_title; }
<?php if (function_exists('wc_print_messages')) { wc_print_messages(); } else { global $woocommerce; $woocommerce->show_messages(); } ?> <?php if (PV_Vendors::is_pending(get_current_user_id())) { ?> <p><?php _e('Your account has not yet been approved to become a vendor.', 'wc_product_vendor'); ?> </p> <?php } else { ?> <p><?php _e('Your account is not vendor capable.', 'wc_product_vendor'); ?> </p> <?php if (Product_Vendor::$pv_options->get_option('show_vendor_registration')) { ?>
/** * */ function sales() { global $start_date, $end_date, $woocommerce, $wpdb; $start_date = !empty($_POST['start_date']) ? $_POST['start_date'] : strtotime(date('Ymd', strtotime(date('Ym', current_time('timestamp')) . '01'))); $end_date = !empty($_POST['end_date']) ? $_POST['end_date'] : strtotime(date('Ymd', current_time('timestamp'))); if (!empty($_POST['start_date'])) { $start_date = strtotime($_POST['start_date']); } if (!empty($_POST['end_date'])) { $end_date = strtotime($_POST['end_date']); } $after = date('Y-m-d', $start_date); $before = date('Y-m-d', strtotime('+1 day', $end_date)); $commission_due = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'due'\n\t\t\tAND time >= '" . $after . "'\n\t\t\tAND time <= '" . $before . "'\n\t\t"); $reversed = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'reversed'\n\t\t\tAND time >= '" . $after . "'\n\t\t\tAND time <= '" . $before . "'\n\t\t"); $paid = $wpdb->get_var("\n\t\t\tSELECT SUM(total_due + total_shipping + tax) FROM {$wpdb->prefix}pv_commission WHERE status = 'paid'\n\t\t\tAND time >= '" . $after . "'\n\t\t\tAND time <= '" . $before . "'\n\t\t"); ?> <form method="post" action=""> <p><label for="from"><?php _e('From:', 'wc_product_vendor'); ?> </label> <input type="text" name="start_date" id="from" readonly="readonly" value="<?php echo esc_attr(date('Y-m-d', $start_date)); ?> "/> <label for="to"><?php _e('To:', 'wc_product_vendor'); ?> </label> <input type="text" name="end_date" id="to" readonly="readonly" value="<?php echo esc_attr(date('Y-m-d', $end_date)); ?> "/> <input type="submit" class="button" value="<?php _e('Show', 'wc_product_vendor'); ?> "/></p> </form> <script type="text/javascript"> jQuery(function () { <?php woocommerce_datepicker_js(); ?> }); </script> <div id="poststuff" class="woocommerce-reports-wrap"> <div class="woocommerce-reports-sidebar"> <div class="postbox"> <h3><span><?php _e('Total paid in range', 'wc_product_vendor'); ?> </span></h3> <div class="inside"> <p class="stat"><?php if ($paid > 0) { echo woocommerce_price($paid); } else { _e('n/a', 'wc_product_vendor'); } ?> </p> </div> </div> <div class="postbox"> <h3><span><?php _e('Total due in range', 'wc_product_vendor'); ?> </span></h3> <div class="inside"> <p class="stat"><?php if ($commission_due > 0) { echo woocommerce_price($commission_due); } else { _e('n/a', 'wc_product_vendor'); } ?> </p> </div> </div> <div class="postbox"> <h3><span><?php _e('Total reversed in range', 'wc_product_vendor'); ?> </span></h3> <div class="inside"> <p class="stat"><?php if ($reversed > 0) { echo woocommerce_price($reversed); } else { _e('n/a', 'wc_product_vendor'); } ?> </p> </div> </div> </div> <div class="woocommerce-reports-main"> <div class="postbox"> <h3><span><?php _e('Recent Commission', 'wc_product_vendor'); ?> </span></h3> <div> <?php $commission = $wpdb->get_results("\n\t\t\t\t\t\t\t\tSELECT * FROM {$wpdb->prefix}pv_commission\n\t\t\t\t\t\t\t\tORDER BY time DESC\n\t\t\t\t\t\t\t\tLIMIT 20\n\t\t\t\t\t\t\t"); if (sizeof($commission) > 0) { ?> <div class="woocommerce_order_items_wrapper"> <table id="commission-table" class="woocommerce_order_items" cellspacing="0"> <thead> <tr> <th><?php _e('Order', 'wc_product_vendor'); ?> </th> <th><?php _e('Product', 'wc_product_vendor'); ?> </th> <th><?php _e('Vendor', 'wc_product_vendor'); ?> </th> <th><?php _e('Total', 'wc_product_vendor'); ?> </th> <th><?php _e('Date & Time', 'wc_product_vendor'); ?> </th> <th><?php _e('Status', 'wc_product_vendor'); ?> </th> </tr> </thead> <tbody> <?php $i = 1; foreach ($commission as $row) { $i++; ?> <tr<?php if ($i % 2 == 1) { echo ' class="alternate"'; } ?> > <td><?php if ($row->order_id) { ?> <a href="<?php echo admin_url('post.php?post=' . $row->order_id . '&action=edit'); ?> "><?php echo $row->order_id; ?> </a><?php } else { _e('N/A', 'wc_product_vendor'); } ?> </td> <td><?php echo get_the_title($row->product_id); ?> </td> <td><?php echo PV_Vendors::get_vendor_shop_name($row->vendor_id); ?> </td> <td><?php echo woocommerce_price($row->total_due + $row->total_shipping + $row->tax); ?> </td> <td><?php echo date(__('D j M Y \\a\\t h:ia', 'wc_product_vendor'), strtotime($row->time)); ?> </td> <td><?php echo $row->status; ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php } else { ?> <p><?php _e('No commission yet', 'wc_product_vendor'); ?> </p><?php } ?> </div> </div> </div> </div> <?php }
/** * Update oustanding commission for a vendor * * @param int $vendor_id * @param float $total * * @return bool */ public static function update_total_due($vendor_id, $total) { $new_total = $total += PV_Vendors::get_total_due($vendor_id); return update_user_meta($vendor_id, 'pv_total_due', $new_total); }
/** * * * @param unknown $items * @param unknown $order * * @return unknown */ public function check_items($items, $order) { foreach ($items as $key => $product) { if (empty($product['product_id'])) { unset($items[$key]); continue; } $author = PV_Vendors::get_vendor_from_product($product['product_id']); if ($this->current_vendor != $author) { unset($items[$key]); continue; } else { $commission_due = PV_Commission::calculate_commission($product['line_subtotal'], $product['product_id'], $order); $items[$key]['line_subtotal'] = $commission_due; $items[$key]['line_total'] = $commission_due; unset($items[$key]['line_tax']); } } return $items; }
/** * Use views to display the Orders page * * @return html */ public function display_product_orders() { if (!PV_Vendors::is_vendor(get_current_user_id())) { ob_start(); woocommerce_get_template('denied.php', array(), 'wc-product-vendor/dashboard/', pv_plugin_dir . 'views/dashboard/'); return ob_get_clean(); } if (empty($_GET['orders_for_product'])) { return __('You haven\'t selected a product\'s orders to view! Please go back to the Vendor Dashboard and click Show Orders on the product you\'d like to view.', 'wc_product_vendor'); } if (!$this->orders) { return __('No orders.', 'wc_product_vendor'); } if (!empty($_POST['submit_comment'])) { require_once pv_plugin_dir . 'classes/front/orders/class-submit-comment.php'; PV_Submit_Comment::new_comment($this->orders); } if (isset($_POST['mark_shipped'])) { $order_id = (int) $_POST['order_id']; $product_id = (int) $_POST['product_id']; exit; } if (isset($_POST['update_tracking'])) { $order_id = (int) $_POST['order_id']; $product_id = (int) $_POST['product_id']; $tracking_provider = woocommerce_clean($_POST['tracking_provider']); $custom_tracking_provider = woocommerce_clean($_POST['custom_tracking_provider']); $custom_tracking_link = woocommerce_clean($_POST['custom_tracking_link']); $tracking_number = woocommerce_clean($_POST['tracking_number']); $date_shipped = woocommerce_clean(strtotime($_POST['date_shipped'])); $order = new WC_Order($order_id); $products = $order->get_items(); foreach ($products as $key => $value) { if ($value['product_id'] == $product_id || $value['variation_id'] == $product_id) { $order_item_id = $key; break; } } if ($order_item_id) { woocommerce_delete_order_item_meta(2048, __('Tracking number', 'wc_product_vendor')); woocommerce_add_order_item_meta(2048, __('Tracking number', 'wc_product_vendor'), $tracking_number); $message = __('Success. Your tracking number has been updated.', 'wc_product_vendor'); if (function_exists('wc_add_message')) { wc_add_message($message); } else { $woocommerce->add_message($message); } // Update order data update_post_meta($order_id, '_tracking_provider', $tracking_provider); update_post_meta($order_id, '_custom_tracking_provider', $custom_tracking_provider); update_post_meta($order_id, '_tracking_number', $tracking_number); update_post_meta($order_id, '_custom_tracking_link', $custom_tracking_link); update_post_meta($order_id, '_date_shipped', $date_shipped); } } $headers = PV_Orders::get_headers(); $all = PV_Orders::format_order_details($this->orders, $this->product_id); wp_enqueue_style('pv_frontend_style', pv_assets_url . 'css/pv-frontend.css'); wp_enqueue_script('pv_frontend_script', pv_assets_url . 'js/front-orders.js'); // WC Shipment Tracking Providers global $WC_Shipment_Tracking; $providers = !empty($WC_Shipment_Tracking->providers) ? $WC_Shipment_Tracking->providers : false; $provider_array = array(); if ($providers) { foreach ($providers as $providerss) { foreach ($providerss as $provider => $format) { $provider_array[sanitize_title($provider)] = urlencode($format); } } } // End ob_start(); // Show the Export CSV button if ($this->can_export_csv) { woocommerce_get_template('csv-export.php', array(), 'wc-product-vendor/orders/', pv_plugin_dir . 'views/orders/'); } woocommerce_get_template('orders.php', array('headers' => $headers, 'body' => $all['body'], 'items' => $all['items'], 'product_id' => $all['product_id'], 'providers' => $providers, 'provider_array' => $provider_array), 'wc-product-vendor/orders/', pv_plugin_dir . 'views/orders/'); return ob_get_clean(); }
/** * * * @param unknown $order * @param unknown $author_email * @param unknown $setPaymentOptionsRequest * @param unknown $is_admin (optional) * * @return unknown */ public function set_vendor_items($order, $setPaymentOptionsRequest) { $receivers = PV_Vendors::get_vendor_dues_from_order($order, false); foreach ($receivers as $products) { $invoice_items = array(); $shipping_given = $tax_given = 0; foreach ($products as $key => $product) { $product_id = $product['product_id']; $shipping_given += $product['shipping']; $tax_given += $product['tax']; if (!empty($product['commission'])) { $item = new InvoiceItem(); $item->name = get_the_title($product_id); $item->identifier = $product_id; $item->price = $product['commission']; $item->itemPrice = round($product['commission'] / $product['qty'], 2); $item->itemCount = $product['qty']; $invoice_items[] = $item; } } if (empty($invoice_items)) { continue; } $receiverOptions = new ReceiverOptions(); $setPaymentOptionsRequest->receiverOptions[] = $receiverOptions; // Set the current vendor $receiverId = new ReceiverIdentifier(); $receiverId->email = $product['vendor_id'] == 1 ? $this->main_paypal : PV_Vendors::get_vendor_paypal($product['vendor_id']); $receiverOptions->receiver = $receiverId; $receiverOptions->invoiceData = new InvoiceData(); $receiverOptions->invoiceData->item = $invoice_items; $receiverOptions->invoiceData->totalTax = $tax_given; $receiverOptions->invoiceData->totalShipping = $shipping_given; } return $setPaymentOptionsRequest; }
/** * * * @return unknown */ public function can_view_vendor_page() { if (!is_user_logged_in()) { return false; } else { if (!PV_Vendors::is_vendor(get_current_user_id())) { woocommerce_get_template('denied.php', array(), 'wc-product-vendor/dashboard/', pv_plugin_dir . 'views/dashboard/'); return false; } } return true; }
/** * * * @param unknown $ids (optional) * * @return unknown */ public function mark_due($ids = array()) { global $wpdb; $table_name = $wpdb->prefix . "pv_commission"; $query = "SELECT sum(`total_due` + `total_shipping` + `tax`) as total, `vendor_id` FROM `{$table_name}` WHERE `status` != 'due' AND `id` IN ({$ids}) GROUP BY `vendor_id`"; $dues = $wpdb->get_results($query); if (empty($dues)) { return false; } foreach ($dues as $due) { PV_Vendors::update_total_due($due->vendor_id, $due->total); } $query = "UPDATE `{$table_name}` SET `status` = 'due' WHERE id IN ({$ids})"; $result = $wpdb->query($query); return $result; }
/** * */ public function sold_by_meta() { $author_id = get_the_author_meta('ID'); $sold_by = PV_Vendors::is_vendor($author_id) ? sprintf('<a href="%s" target="_TOP">%s</a>', PV_Vendors::get_vendor_shop_page($author_id), PV_Vendors::get_vendor_shop_name($author_id)) : get_bloginfo('name'); echo __('Sold by', 'wc_product_vendor') . ': ' . $sold_by . '<br/>'; }