Exemplo n.º 1
0
 /**
  * Submit a comment for an order
  *
  * @param object $orders
  *
  * @return unknown
  */
 public static function new_comment($orders)
 {
     global $woocommerce;
     $user = wp_get_current_user();
     $user = $user->ID;
     // Security
     if (!wp_verify_nonce($_POST['_wpnonce'], 'add-comment')) {
         return false;
     }
     // Check if this product belongs to the vendor submitting the comment
     $product_id = (int) $_POST['product_id'];
     $author = PV_Vendors::get_vendor_from_product($product_id);
     if ($author != $user) {
         return false;
     }
     // Find the order belonging to this comment
     foreach ($orders as $order) {
         if ($order->order_id == $_POST['order_id']) {
             $found_order = $order;
             break;
         }
     }
     // No order was found
     if (empty($found_order)) {
         return false;
     }
     // Don't submit empty comments
     if (empty($_POST['comment_text'])) {
         if (function_exists('wc_add_error')) {
             wc_add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor'));
         } else {
             $woocommerce->add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor'));
         }
         return false;
     }
     // Only submit if the order has the product belonging to this vendor
     $found_order = new WC_Order($found_order->order_id);
     $valid_order = false;
     foreach ($found_order->get_items() as $item) {
         if ($item['product_id'] == $product_id) {
             $valid_order = true;
             break;
         }
     }
     if ($valid_order) {
         $comment = esc_textarea($_POST['comment_text']);
         add_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
         $found_order->add_order_note($comment, 1);
         remove_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
         if (function_exists('wc_add_message')) {
             wc_add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor'));
         } else {
             $woocommerce->add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor'));
         }
     }
 }
Exemplo n.º 2
0
 public function save_vendor_settings()
 {
     if (empty($_POST['vendor_application_submit'])) {
         return false;
     }
     if (!wp_verify_nonce($_POST['wc-product-vendor-nonce'], 'save-shop-settings')) {
         return false;
     }
     global $woocommerce;
     $user_id = get_current_user_id();
     if (isset($_POST['pv_paypal'])) {
         if (!is_email($_POST['pv_paypal'])) {
             if (function_exists('wc_add_error')) {
                 wc_add_error(__('Your PayPal address is not a valid email address.', 'wc_product_vendor'));
             } else {
                 $woocommerce->add_error(__('Your PayPal address is not a valid email address.', 'wc_product_vendor'));
             }
         } else {
             update_user_meta($user_id, 'pv_paypal', $_POST['pv_paypal']);
         }
     }
     if (!empty($_POST['pv_shop_name'])) {
         $users = get_users(array('meta_key' => 'pv_shop_slug', 'meta_value' => sanitize_title($_POST['pv_shop_name'])));
         if (!empty($users) && $users[0]->ID != $user_id) {
             if (function_exists('wc_add_error')) {
                 wc_add_error(__('That shop name is already taken. Your shop name must be unique.', 'wc_product_vendor'));
             } else {
                 $woocommerce->add_error(__('That shop name is already taken. Your shop name must be unique.', 'wc_product_vendor'));
             }
         } else {
             update_user_meta($user_id, 'pv_shop_name', $_POST['pv_shop_name']);
             update_user_meta($user_id, 'pv_shop_slug', sanitize_title($_POST['pv_shop_name']));
         }
     }
     if (isset($_POST['pv_shop_description'])) {
         update_user_meta($user_id, 'pv_shop_description', $_POST['pv_shop_description']);
     }
     if (isset($_POST['pv_seller_info'])) {
         update_user_meta($user_id, 'pv_seller_info', $_POST['pv_seller_info']);
     }
     do_action('wc_product_vendor_shop_settings_saved', $user_id);
     if (!$woocommerce->error_count()) {
         if (function_exists('wc_add_message')) {
             wc_add_message(__('Settings saved.', 'wc_product_vendor'));
         } else {
             $woocommerce->add_message(__('Settings saved.', 'wc_product_vendor'));
         }
     }
 }
 /**
  * Process the add payment method form.
  */
 public static function add_payment_method_action()
 {
     if (isset($_POST['woocommerce_add_payment_method']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-add-payment-method')) {
         ob_start();
         $payment_method = wc_clean($_POST['payment_method']);
         $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
         // Validate
         $available_gateways[$payment_method]->validate_fields();
         // Process
         if (wc_notice_count('wc_errors') == 0) {
             $result = $available_gateways[$payment_method]->add_payment_method();
             // Redirect to success/confirmation/payment page
             if ($result['result'] == 'success') {
                 wc_add_message(__('Payment method added.', 'woocommerce'));
                 wp_redirect($result['redirect']);
                 exit;
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  *
  *
  * @param unknown $user_id
  */
 public function save_pending($user_id)
 {
     if (isset($_POST['apply_for_vendor'])) {
         global $woocommerce;
         if (function_exists('wc_clear_messages')) {
             wc_clear_messages();
         } else {
             $woocommerce->clear_messages();
         }
         if (user_can($user_id, 'manage_options')) {
             if (function_exists('wc_add_error')) {
                 wc_add_error(__('Application denied. You are an administrator.', 'wc_product_vendor'));
             } else {
                 $woocommerce->add_error(__('Application denied. You are an administrator.', 'wc_product_vendor'));
             }
         } else {
             if (function_exists('wc_add_message')) {
                 wc_add_message(__('Your application has been submitted.', 'wc_product_vendor'));
             } else {
                 $woocommerce->add_message(__('Your application has been submitted.', 'wc_product_vendor'));
             }
             $manual = Product_Vendor::$pv_options->get_option('manual_vendor_registration');
             $role = apply_filters('wc_product_vendor_pending_role', $manual ? 'pending_vendor' : 'vendor');
             $wp_user_object = new WP_User($user_id);
             $wp_user_object->set_role($role);
             do_action('wc_product_vendor_application_submited', $user_id);
             add_filter('woocommerce_registration_redirect', array('PV_Vendor_Signup', 'redirect_to_vendor_dash'));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Use views to display the Orders page
  *
  * @return html
  */
 public function display_product_orders()
 {
     if (!WCV_Vendors::is_vendor(get_current_user_id())) {
         ob_start();
         woocommerce_get_template('denied.php', array(), 'wc-product-vendor/dashboard/', wcv_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.', 'wcvendors');
     }
     if (!$this->orders) {
         return __('No orders.', 'wcvendors');
     }
     if (!empty($_POST['submit_comment'])) {
         require_once wcv_plugin_dir . 'classes/front/orders/class-submit-comment.php';
         WCV_Submit_Comment::new_comment($this->orders);
     }
     if (isset($_POST['mark_shipped'])) {
         $order_id = (int) $_POST['order_id'];
         $product_id = (int) $_POST['product_id'];
         exit;
     }
     if (isset($_POST['update_tracking'])) {
         $order_id = (int) $_POST['order_id'];
         $product_id = (int) $_POST['product_id'];
         $tracking_provider = woocommerce_clean($_POST['tracking_provider']);
         $custom_tracking_provider = woocommerce_clean($_POST['custom_tracking_provider']);
         $custom_tracking_link = woocommerce_clean($_POST['custom_tracking_link']);
         $tracking_number = woocommerce_clean($_POST['tracking_number']);
         $date_shipped = woocommerce_clean(strtotime($_POST['date_shipped']));
         $order = new WC_Order($order_id);
         $products = $order->get_items();
         foreach ($products as $key => $value) {
             if ($value['product_id'] == $product_id || $value['variation_id'] == $product_id) {
                 $order_item_id = $key;
                 break;
             }
         }
         if ($order_item_id) {
             woocommerce_delete_order_item_meta(2048, __('Tracking number', 'wcvendors'));
             woocommerce_add_order_item_meta(2048, __('Tracking number', 'wcvendors'), $tracking_number);
             $message = __('Success. Your tracking number has been updated.', 'wcvendors');
             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 = WCV_Orders::get_headers();
     $all = WCV_Orders::format_order_details($this->orders, $this->product_id);
     wp_enqueue_style('pv_frontend_style', wcv_assets_url . 'css/pv-frontend.css');
     wp_enqueue_script('pv_frontend_script', wcv_assets_url . 'js/front-orders.js');
     // WC Shipment Tracking Providers
     global $WC_Shipment_Tracking;
     $providers = !empty($WC_Shipment_Tracking->providers) ? $WC_Shipment_Tracking->providers : false;
     $provider_array = array();
     if ($providers) {
         foreach ($providers as $providerss) {
             foreach ($providerss as $provider => $format) {
                 $provider_array[sanitize_title($provider)] = urlencode($format);
             }
         }
     }
     // End
     ob_start();
     // Show the Export CSV button
     if ($this->can_export_csv) {
         woocommerce_get_template('csv-export.php', array(), 'wc-product-vendor/orders/', wcv_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/', wcv_plugin_dir . 'views/orders/');
     return ob_get_clean();
 }
Exemplo n.º 6
0
 public function save_vendor_settings()
 {
     global $woocommerce;
     $user_id = get_current_user_id();
     if (!empty($_GET['wc_pv_mark_shipped'])) {
         $order_id = $_GET['wc_pv_mark_shipped'];
         $shippers = (array) get_post_meta($order_id, 'wc_pv_shipped', true);
         if (in_array($user_id, $shippers)) {
             foreach ($shippers as $key => $value) {
                 if ($value == $user_id) {
                     unset($shippers[$key]);
                     if (function_exists('wc_add_error')) {
                         wc_add_error(__('Order unmarked shipped.', 'wcvendors'));
                     } else {
                         $woocommerce->add_error(__('Order unmarked shipped.', 'wcvendors'));
                     }
                     break;
                 }
             }
         } else {
             $shippers[] = $user_id;
             $mails = $woocommerce->mailer()->get_emails();
             if (!empty($mails)) {
                 $mails['WC_Email_Notify_Shipped']->trigger($order_id, $user_id);
             }
             if (function_exists('wc_add_message')) {
                 wc_add_message(__('Order marked shipped.', 'wcvendors'));
             } else {
                 $woocommerce->add_message(__('Order marked shipped.', 'wcvendors'));
             }
         }
         update_post_meta($order_id, 'wc_pv_shipped', $shippers);
         return;
     }
     if (empty($_POST['vendor_application_submit'])) {
         return false;
     }
     if (!wp_verify_nonce($_POST['wc-product-vendor-nonce'], 'save-shop-settings')) {
         return false;
     }
     if (isset($_POST['pv_paypal'])) {
         if (!is_email($_POST['pv_paypal'])) {
             if (function_exists('wc_add_error')) {
                 wc_add_error(__('Your PayPal address is not a valid email address.', 'wcvendors'));
             } else {
                 $woocommerce->add_error(__('Your PayPal address is not a valid email address.', 'wcvendors'));
             }
         } else {
             update_user_meta($user_id, 'pv_paypal', $_POST['pv_paypal']);
         }
     }
     if (!empty($_POST['pv_shop_name'])) {
         $users = get_users(array('meta_key' => 'pv_shop_slug', 'meta_value' => sanitize_title($_POST['pv_shop_name'])));
         if (!empty($users) && $users[0]->ID != $user_id) {
             if (function_exists('wc_add_error')) {
                 wc_add_error(__('That shop name is already taken. Your shop name must be unique.', 'wcvendors'));
             } else {
                 $woocommerce->add_error(__('That shop name is already taken. Your shop name must be unique.', 'wcvendors'));
             }
         } else {
             update_user_meta($user_id, 'pv_shop_name', $_POST['pv_shop_name']);
             update_user_meta($user_id, 'pv_shop_slug', sanitize_title($_POST['pv_shop_name']));
         }
     }
     if (isset($_POST['pv_shop_description'])) {
         update_user_meta($user_id, 'pv_shop_description', $_POST['pv_shop_description']);
     }
     if (isset($_POST['pv_seller_info'])) {
         update_user_meta($user_id, 'pv_seller_info', $_POST['pv_seller_info']);
     }
     do_action('wcvendors_shop_settings_saved', $user_id);
     if (!wc_notice_count()) {
         if (function_exists('wc_add_message')) {
             wc_add_message(__('Settings saved.', 'wcvendors'));
         } else {
             wc_add_notice(__('Settings saved.', 'wcvendors'));
         }
     }
 }