/** * 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')); } } }
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')); } } }
/** * * * @return unknown */ public function apply_form() { global $woocommerce; if (!isset($_POST['apply_for_vendor'])) { return false; } if ($this->terms_page && !isset($_POST['agree_to_terms'])) { if (function_exists('wc_clear_messages')) { wc_clear_messages(); } else { $woocommerce->clear_messages(); } if (function_exists('wc_add_error')) { wc_add_error(__('You must accept the terms and conditions to become a vendor.', 'wc_product_vendor')); } else { $woocommerce->add_error(__('You must accept the terms and conditions to become a vendor.', 'wc_product_vendor')); } } else { if (isset($_POST['apply_for_vendor_submit'])) { self::save_pending(get_current_user_id()); } } }
/** * * * @param unknown $pay_key * @param unknown $order_id * * @return unknown */ public function set_paypal_author_specifics($pay_key, $order_id) { global $woocommerce; $this->include_paypal_sdk(); $order = new WC_Order($order_id); // Create request $setPaymentOptionsRequest = new SetPaymentOptionsRequest(new RequestEnvelope("en_US")); $setPaymentOptionsRequest->payKey = $pay_key; if ($this->instapay) { $setPaymentOptionsRequest = $this->set_vendor_items($order, $setPaymentOptionsRequest); } if ($this->debug_me) { foreach ($setPaymentOptionsRequest->receiverOptions as $k) { var_dump($k->invoiceData); } exit; } $setPaymentOptionsRequest->senderOptions = new SenderOptions(); $setPaymentOptionsRequest->senderOptions->requireShippingAddressSelection = true; $service = new AdaptivePaymentsService(); try { $response = $service->SetPaymentOptions($setPaymentOptionsRequest); } catch (Exception $ex) { if (function_exists('wc_add_error')) { wc_add_error(sprintf(__('Error: %s', 'wc_product_vendor'), $ex->getMessage())); } else { $woocommerce->add_error(sprintf(__('Error: %s', 'wc_product_vendor'), $ex->getMessage())); } return false; } $this->logger->error("Received SetPaymentOptionsResponse:"); $ack = strtoupper($response->responseEnvelope->ack); if ($ack != "SUCCESS") { $order->update_status('cancelled', __(sprintf('Error ID: %s. %s', $response->error[0]->errorId, $response->error[0]->message), 'wc_product_vendor')); if (function_exists('wc_add_error')) { wc_add_error(sprintf('Error ID: %s. %s', $response->error[0]->errorId, $response->error[0]->message)); } else { $woocommerce->add_error(sprintf('Error ID: %s. %s', $response->error[0]->errorId, $response->error[0]->message)); } return false; } return true; }
/** * Add error message in checkout. * * @param string $message Error message. * * @return string Displays the error message. */ protected function add_error($message) { global $woocommerce; if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) { wc_add_error($message); } else { $woocommerce->add_error($message); } }
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')); } } }