• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_create_order函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_create_order函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_create_order函数的具体用法?PHP wc_create_order怎么用?PHP wc_create_order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wc_create_order函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: create_order

 /**
  * Create a order.
  *
  * @since 2.4
  *
  * @return WC_Order Order object.
  */
 public static function create_order()
 {
     // Create product
     $product = WC_Helper_Product::create_simple_product();
     WC_Helper_Shipping::create_simple_flat_rate();
     $order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => '');
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     // Required, else wc_create_order throws an exception
     $order = wc_create_order($order_data);
     // Add order products
     $item_id = $order->add_product($product, 4);
     // Set billing address
     $billing_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => '[email protected]', 'phone' => '555-32123');
     $order->set_address($billing_address, 'billing');
     // Add shipping costs
     $shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
     $order->add_shipping(new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate'));
     // Set payment gateway
     $payment_gateways = WC()->payment_gateways->payment_gateways();
     $order->set_payment_method($payment_gateways['bacs']);
     // Set totals
     $order->set_total(10, 'shipping');
     $order->set_total(0, 'cart_discount');
     $order->set_total(0, 'cart_discount_tax');
     $order->set_total(0, 'tax');
     $order->set_total(0, 'shipping_tax');
     $order->set_total(40, 'total');
     // 4 x $10 simple helper product
     return wc_get_order($order->id);
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:37,代码来源:class-wc-helper-order.php


示例2: update_order

 public function update_order($data, $iopn_record_id)
 {
     global $wpdb, $woocommerce;
     $prefix = $wpdb->prefix . 'pwa_';
     $xml = simplexml_load_string($data);
     $NotificationReferenceId = $xml->NotificationReferenceId;
     $OrderChannel = $xml->ProcessedOrder->OrderChannel;
     $AmazonOrderID = (string) $xml->ProcessedOrder->AmazonOrderID;
     $OrderDate = $xml->ProcessedOrder->OrderDate;
     $param['NotificationReferenceId'] = $NotificationReferenceId;
     $param['AmazonOrderID'] = $AmazonOrderID;
     $param['iopn_record_id'] = $iopn_record_id;
     $order_postmeta = $wpdb->get_results("select post_id from {$wpdb->postmeta} where meta_key = '_pwa_order_id' and meta_value = '{$AmazonOrderID}' ");
     if (empty($order_postmeta)) {
         $request_time = $wpdb->get_results("select * from `" . $prefix . "iopn_records` where amazon_order_id = '{$AmazonOrderID}' and notification_reference_id = '{$NotificationReferenceId}' and status = 'Rejected' ");
         if (!empty($request_time)) {
             $param['Status'] = 'Accepted';
             $this->update_request($param);
             $order = wc_create_order();
             add_post_meta($order->id, '_pwa_order_id', $AmazonOrderID);
             $this->update_order_detail($order->id, $data);
         } else {
             $param['Status'] = 'Rejected';
             $this->update_request($param);
             header('HTTP/1.1 503 SERVICE_UNAVAILABLE');
             exit;
         }
     } else {
         $param['Status'] = 'Accepted';
         $this->update_request($param);
         $order_id = $order_postmeta[0]->post_id;
         $this->update_order_detail($order_id, $data);
     }
 }
开发者ID:booklein,项目名称:wpbookle,代码行数:34,代码来源:NewOrderNotification.php


示例3: create_order

 /**
  * Create a order.
  *
  * @since 2.4
  *
  * @return WC_Order Order object.
  */
 public static function create_order($customer_id = 1)
 {
     // Create product
     $product = WC_Helper_Product::create_simple_product();
     WC_Helper_Shipping::create_simple_flat_rate();
     $order_data = array('status' => 'pending', 'customer_id' => $customer_id, 'customer_note' => '', 'total' => '');
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     // Required, else wc_create_order throws an exception
     $order = wc_create_order($order_data);
     // Add order products
     $order->add_product($product, 4);
     // Set billing address
     $order->set_billing_first_name('Jeroen');
     $order->set_billing_last_name('Sormani');
     $order->set_billing_company('WooCompany');
     $order->set_billing_address_1('WooAddress');
     $order->set_billing_address_2('');
     $order->set_billing_city('WooCity');
     $order->set_billing_state('NY');
     $order->set_billing_postcode('123456');
     $order->set_billing_country('US');
     $order->set_billing_email('[email protected]');
     $order->set_billing_phone('555-32123');
     // Add shipping costs
     $shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
     $rate = new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate');
     $item = new WC_Order_Item_Shipping();
     $item->set_props(array('method_title' => $rate->label, 'method_id' => $rate->id, 'total' => wc_format_decimal($rate->cost), 'taxes' => $rate->taxes, 'meta_data' => $rate->get_meta_data()));
     $order->add_item($item);
     // Set payment gateway
     $payment_gateways = WC()->payment_gateways->payment_gateways();
     $order->set_payment_method($payment_gateways['bacs']);
     // Set totals
     $order->set_shipping_total(10);
     $order->set_discount_total(0);
     $order->set_discount_tax(0);
     $order->set_cart_tax(0);
     $order->set_shipping_tax(0);
     $order->set_total(40);
     // 4 x $10 simple helper product
     $order->save();
     return $order;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:50,代码来源:class-wc-helper-order.php


示例4: create_base_order

 /**
  * Creates new WC_Order.
  *
  * @since 3.0.0
  * @param $args array
  * @return WC_Order
  */
 private function create_base_order($args, $data)
 {
     return wc_create_order($args);
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:11,代码来源:class-wc-csv-import-suite-order-import.php


示例5: create_order

 /**
  * Create an order
  *
  * @since 2.2
  * @param array $data raw order data
  * @return array
  */
 public function create_order($data)
 {
     $data = isset($data['order']) ? $data['order'] : array();
     try {
         // permission check
         if (!current_user_can('publish_shop_orders')) {
             throw new WC_API_Exception('woocommerce_api_user_cannot_create_order', __('You do not have permission to create orders', 'woocommerce'), 401);
         }
         $data = apply_filters('woocommerce_api_create_order_data', $data, $this);
         // default order args, note that status is checked for validity in wc_create_order()
         $default_order_args = array('status' => isset($data['status']) ? $data['status'] : '', 'customer_note' => isset($data['note']) ? $data['note'] : null);
         // if creating order for existing customer
         if (!empty($data['customer_id'])) {
             // make sure customer exists
             if (false === get_user_by('id', $data['customer_id'])) {
                 throw new WC_API_Exception('woocommerce_api_invalid_customer_id', __('Customer ID is invalid', 'woocommerce'), 400);
             }
             $default_order_args['customer_id'] = $data['customer_id'];
         }
         // create the pending order
         $order = wc_create_order($default_order_args);
         if (is_wp_error($order)) {
             throw new WC_API_Exception('woocommerce_api_cannot_create_order', sprintf(__('Cannot create order: %s', 'woocommerce'), implode(', ', $order->get_error_messages())), 400);
         }
         // billing/shipping addresses
         $this->set_order_addresses($order, $data);
         $lines = array('line_item' => 'line_items', 'shipping' => 'shipping_lines', 'fee' => 'fee_lines', 'coupon' => 'coupon_lines');
         foreach ($lines as $line_type => $line) {
             if (isset($data[$line]) && is_array($data[$line])) {
                 $set_item = "set_{$line_type}";
                 foreach ($data[$line] as $item) {
                     $this->{$set_item}($order, $item, 'create');
                 }
             }
         }
         // calculate totals and set them
         $order->calculate_totals();
         // payment method (and payment_complete() if `paid` == true)
         if (isset($data['payment_details']) && is_array($data['payment_details'])) {
             // method ID & title are required
             if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) {
                 throw new WC_API_Exception('woocommerce_invalid_payment_details', __('Payment method ID and title are required', 'woocommerce'), 400);
             }
             update_post_meta($order->id, '_payment_method', $data['payment_details']['method_id']);
             update_post_meta($order->id, '_payment_method_title', $data['payment_details']['method_title']);
             // mark as paid if set
             if (isset($data['payment_details']['paid']) && 'true' === $data['payment_details']['paid']) {
                 $order->payment_complete(isset($data['payment_details']['transaction_id']) ? $data['payment_details']['transaction_id'] : '');
             }
         }
         // set order currency
         if (isset($data['currency'])) {
             if (!array_key_exists($data['currency'], get_woocommerce_currencies())) {
                 throw new WC_API_Exception('woocommerce_invalid_order_currency', __('Provided order currency is invalid', 'woocommerce'), 400);
             }
             update_post_meta($order->id, '_order_currency', $data['currency']);
         }
         // set order number
         if (isset($data['order_number'])) {
             update_post_meta($order->id, '_order_number', $data['order_number']);
         }
         // set order meta
         if (isset($data['order_meta']) && is_array($data['order_meta'])) {
             $this->set_order_meta($order->id, $data['order_meta']);
         }
         // HTTP 201 Created
         $this->server->send_status(201);
         wc_delete_shop_order_transients($order->id);
         do_action('woocommerce_api_create_order', $order->id, $this);
         return $this->get_order($order->id);
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:81,代码来源:class-wc-api-orders.php


示例6: sync


//.........这里部分代码省略.........
                         if (username_exists($username)) {
                             $counter = 1;
                             $newusername = $username . $counter;
                             while (username_exists($newusername)) {
                                 $counter++;
                                 $newusername = $username . $counter;
                             }
                             $username = $newusername;
                         }
                         $password = wp_generate_password();
                         $customer_data = apply_filters('woocommerce_new_customer_data', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'role' => 'customer'));
                         $customer_id = wp_insert_user($customer_data);
                         foreach ($address_data as $key => $value) {
                             update_user_meta($customer_id, $key, $value);
                         }
                         do_action('woocommerce_created_customer', $customer_id, $customer_data, true);
                     } else {
                         $customer_id = $user->ID;
                     }
                 } else {
                     $customer_id = 0;
                 }
                 $customer_note = @count($ordercontent->instructions) ? strval($ordercontent->instructions) : '';
                 $order_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM `{$wpdb->prefix}posts` AS P WHERE ID IN (SELECT post_id FROM `{$wpdb->prefix}postmeta` WHERE meta_key = '_codisto_orderid' AND meta_value = %d)", (int) $ordercontent->orderid));
                 $shipping = 0;
                 $shipping_tax = 0;
                 $cart_discount = 0;
                 $cart_discount_tax = 0;
                 $total = (double) $ordercontent->ordertotal;
                 $tax = 0;
                 if (!$order_id) {
                     $new_order_data_callback = array($this, 'order_set_date');
                     add_filter('woocommerce_new_order_data', $new_order_data_callback, 1, 1);
                     $order = wc_create_order(array('customer_id' => $customer_id, 'customer_note' => $customer_note, 'created_via' => 'eBay'));
                     remove_filter('woocommerce_new_order_data', $new_order_data_callback);
                     $order_id = $order->id;
                     update_post_meta($order_id, '_codisto_orderid', (int) $ordercontent->orderid);
                     update_post_meta($order_id, '_codisto_ebayuser', (string) $ordercontent->ebayusername);
                     update_post_meta($order_id, '_order_currency', (string) $ordercontent->transactcurrency);
                     update_post_meta($order_id, '_customer_ip_address', '-');
                     delete_post_meta($order_id, '_prices_include_tax');
                     do_action('woocommerce_new_order', $order_id);
                     foreach ($ordercontent->orderlines->orderline as $orderline) {
                         if ($orderline->productcode[0] != 'FREIGHT') {
                             $productcode = (string) $orderline->productcode;
                             if ($productcode == null) {
                                 $productcode = '';
                             }
                             $productname = (string) $orderline->productname;
                             if ($productname == null) {
                                 $productname = '';
                             }
                             $product_id = $orderline->externalreference[0];
                             if ($product_id != null) {
                                 $product_id = intval($product_id);
                             }
                             $variation_id = 0;
                             if (get_post_type($product_id) === 'product_variation') {
                                 $variation_id = $product_id;
                                 $product_id = wp_get_post_parent_id($variation_id);
                                 if (!is_numeric($product_id) || $product_id === 0) {
                                     $product_id = 0;
                                     $variation_id = 0;
                                 }
                             }
                             $qty = (int) $orderline->quantity[0];
开发者ID:CodistoConnect,项目名称:CodistoConnect-WooCommerce,代码行数:67,代码来源:connect.php


示例7: create_order

 /**
  * Create WC order.
  *
  * @since  2.0.0
  * @access public
  */
 public function create_order()
 {
     if ($this->klarna_debug == 'yes') {
         $this->klarna_log->add('klarna', 'Creating local order...');
     }
     global $woocommerce;
     // Customer accounts
     $customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
     // Order data
     $order_data = array('status' => apply_filters('klarna_checkout_incomplete_order_status', 'kco-incomplete'), 'customer_id' => $customer_id, 'created_via' => 'klarna_checkout');
     // Create the order
     $order = wc_create_order($order_data);
     if (is_wp_error($order)) {
         throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
     }
     if ($this->klarna_debug == 'yes') {
         $this->klarna_log->add('klarna', 'Local order created, order ID: ' . $order->id);
     }
     return $order;
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:26,代码来源:class-klarna-to-wc.php


示例8: fast_order_plugin_cb

function fast_order_plugin_cb()
{
    global $post;
    global $woocommerce;
    global $product;
    global $wp_query;
    parse_str($_POST['formdata'], $formdata);
    $fullname = $formdata['fullname'];
    $address = $formdata['address'];
    $phone = $formdata['telephone'];
    $email = $formdata['email'];
    $pid = $formdata['pid'];
    $qty = $formdata['qty'];
    $flag = 0;
    $report = '<br/>';
    if ($is_alpha_space = ctype_alpha(str_replace(' ', '', $fullname)) && $address != NULL && is_numeric($phone) && $pid != NULL && !$qty <= 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $flag = 1;
    } else {
        if (!($is_alpha_space = ctype_alpha(str_replace(' ', '', $fullname)))) {
            $report .= "Full Name field has an error: " . $fullname . "<br/>";
        }
        if (!$address != NULL) {
            $report .= "Address field has an error: " . $address . "<br/>";
        }
        if (!is_numeric($phone)) {
            $report .= "Phone field has an error: " . $phone . "<br/>";
        }
        if (!$pid != NULL) {
            $report .= "Product id is not correct: " . $pid . "<br/>";
        }
        if ($qty <= 0) {
            $report .= "Quantity field has an error: " . $qty . "<br/>";
        }
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $report .= "Email field has an error: " . $email . "<br/>";
        }
        $flag = 0;
    }
    if ($flag == 1) {
        $address = array('first_name' => $fullname, 'email' => $email, 'phone' => '+92-' . $phone . '', 'address_1' => $address, 'country' => 'PK');
        $order = wc_create_order();
        $order->add_product(get_product($pid), $qty);
        //(get_product with id and next is for quantity)
        $order->set_address($address, 'billing');
        $order->set_address($address, 'shipping');
        $order->calculate_totals();
        $messages = "Thank you " . $fullname . " <br/>Your order has been placed. <br/>You will receive a call from our representative shortly";
    } else {
        $messages = "There is an error in the form <br/> Please correct it" . $report;
    }
    $return_data = array('flag' => $flag, 'messages' => $messages);
    echo json_encode($return_data);
    //echo "Yes! the ajax call was successful"; // this message will be displayed in our jacascript alert
    die(0);
}
开发者ID:shoaibuddin12fx,项目名称:Wordpress-Ajax,代码行数:55,代码来源:plugin.php


示例9: create_order

 /**
  * Create order
  * @param  float $total
  * @param  int $customer_id
  * @return int
  */
 public function create_order($total, $customer_id)
 {
     if (function_exists('wc_create_order')) {
         $order = wc_create_order(array('customer_id' => absint($customer_id)));
         $order_id = $order->id;
         $order->set_total($total);
         update_post_meta($order->id, '_booking_order', '1');
     } else {
         $order_data = apply_filters('woocommerce_new_order_data', array('post_type' => 'shop_order', 'post_title' => sprintf(__('Order &ndash; %s', 'woocommerce-bookings'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce-bookings'))), 'post_status' => 'publish', 'ping_status' => 'closed', 'post_excerpt' => '', 'post_author' => 1, 'post_password' => uniqid('order_')));
         $order_id = wp_insert_post($order_data, true);
         update_post_meta($order_id, '_order_shipping', 0);
         update_post_meta($order_id, '_order_discount', 0);
         update_post_meta($order_id, '_cart_discount', 0);
         update_post_meta($order_id, '_order_tax', 0);
         update_post_meta($order_id, '_order_shipping_tax', 0);
         update_post_meta($order_id, '_order_total', $total);
         update_post_meta($order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_')));
         update_post_meta($order_id, '_customer_user', absint($customer_id));
         update_post_meta($order_id, '_order_currency', get_woocommerce_currency());
         update_post_meta($order_id, '_prices_include_tax', get_option('woocommerce_prices_include_tax'));
         update_post_meta($order_id, '_booking_order', '1');
         wp_set_object_terms($order_id, 'pending', 'shop_order_status');
     }
     do_action('woocommerce_new_booking_order', $order_id);
     return $order_id;
 }
开发者ID:tonyvu1985,项目名称:appletutorings,代码行数:32,代码来源:class-wc-bookings-create.php


示例10: create_order_2_2

 /**
  * Create new order for WooCommerce version 2.2+
  * @return int|WP_ERROR 
  */
 public function create_order_2_2()
 {
     global $woocommerce, $wpdb;
     $this->shipping_methods = WC()->session->get('chosen_shipping_methods');
     if (sizeof($woocommerce->cart->get_cart()) == 0) {
         wc_add_notice(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>', 'hygglig'), home_url()), 'error');
     }
     // Recheck cart items so that they are in stock
     $result = $woocommerce->cart->check_cart_item_stock();
     if (is_wp_error($result)) {
         return $result->get_error_message();
         exit;
     }
     // Update cart totals
     $woocommerce->cart->calculate_totals();
     // Customer accounts
     $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
     // Give plugins the opportunity to create an order themselves
     if ($order_id = apply_filters('woocommerce_create_order', null, $this)) {
         return $order_id;
     }
     try {
         // Start transaction if available
         $wpdb->query('START TRANSACTION');
         $order_data = array('status' => apply_filters('woocommerce_default_order_status', 'pending'), 'customer_id' => $this->customer_id, 'customer_note' => isset($this->posted['order_comments']) ? $this->posted['order_comments'] : '');
         // Insert or update the post data
         $order_id = absint(WC()->session->order_awaiting_payment);
         // Resume the unpaid order if its pending
         if ($order_id > 0 && ($order = wc_get_order($order_id)) && $order->has_status(array('pending', 'failed'))) {
             $order_data['order_id'] = $order_id;
             $order = wc_update_order($order_data);
             if (is_wp_error($order)) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             } else {
                 $order->remove_order_items();
                 do_action('woocommerce_resume_order', $order_id);
             }
         } else {
             $order = wc_create_order($order_data);
             if (is_wp_error($order)) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             } else {
                 $order_id = $order->id;
                 do_action('woocommerce_new_order', $order_id);
             }
         }
         // Store the line items to the new/resumed order
         foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
             $item_id = $order->add_product($values['data'], $values['quantity'], array('variation' => $values['variation'], 'totals' => array('subtotal' => $values['line_subtotal'], 'subtotal_tax' => $values['line_subtotal_tax'], 'total' => $values['line_total'], 'tax' => $values['line_tax'], 'tax_data' => $values['line_tax_data'])));
             if (!$item_id) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             }
             // Allow plugins to add order item meta
             do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
         }
         // Store fees
         foreach (WC()->cart->get_fees() as $fee_key => $fee) {
             $item_id = $order->add_fee($fee);
             if (!$item_id) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             }
             // Allow plugins to add order item meta to fees
             do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
         }
         // Store shipping for all packages
         foreach (WC()->shipping->get_packages() as $package_key => $package) {
             if (isset($package['rates'][$this->shipping_methods[$package_key]])) {
                 $item_id = $order->add_shipping($package['rates'][$this->shipping_methods[$package_key]]);
                 if (!$item_id) {
                     throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
                 }
                 // Allows plugins to add order item meta to shipping
                 do_action('woocommerce_add_shipping_order_item', $order_id, $item_id, $package_key);
             }
         }
         // Store tax rows
         foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
             if (!$order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id))) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             }
         }
         // Store coupons
         foreach (WC()->cart->get_coupons() as $code => $coupon) {
             if (!$order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code))) {
                 throw new Exception(__('Error: Unable to create order. Please try again.', 'woocommerce'));
             }
         }
         // Payment Method
         $available_gateways = WC()->payment_gateways->payment_gateways();
         $this->payment_method = $available_gateways['hygglig_checkout'];
         $order->set_payment_method($this->payment_method);
         $order->set_total(WC()->cart->shipping_total, 'shipping');
         $order->set_total(WC()->cart->get_total_discount(), 'order_discount');
         $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
         $order->set_total(WC()->cart->tax_total, 'tax');
         $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
//.........这里部分代码省略.........
开发者ID:Hygglig,项目名称:New_Hygglig_WooCommerce,代码行数:101,代码来源:class-hygglig-checkout.php


示例11: wcs_create_order_from_subscription

/**
 * Function to create an order from a subscription. It can be used for a renewal or for a resubscribe
 * order creation. It is the common in both of those instances.
 *
 * @param  WC_Subscription|int $subscription Subscription we're basing the order off of
 * @param  string $type        Type of new order. Default values are 'renewal_order'|'resubscribe_order'
 * @return WC_Order            New order
 */
function wcs_create_order_from_subscription($subscription, $type)
{
    $type = wcs_validate_new_order_type($type);
    if (is_wp_error($type)) {
        return $type;
    }
    global $wpdb;
    try {
        $wpdb->query('START TRANSACTION');
        if (!is_object($subscription)) {
            $subscription = wcs_get_subscription($subscription);
        }
        $new_order = wc_create_order(array('customer_id' => $subscription->get_user_id(), 'customer_note' => $subscription->customer_note));
        $new_order->post->post_title = wcs_get_new_order_title($type);
        wcs_copy_order_meta($subscription, $new_order, $type);
        // Copy over line items and allow extensions to add/remove items or item meta
        $items = apply_filters('wcs_new_order_items', $subscription->get_items(array('line_item', 'fee', 'shipping', 'tax')), $new_order, $subscription);
        $items = apply_filters('wcs_' . $type . '_items', $items, $new_order, $subscription);
        foreach ($items as $item_index => $item) {
            $item_name = apply_filters('wcs_new_order_item_name', $item['name'], $item, $subscription);
            $item_name = apply_filters('wcs_' . $type . '_item_name', $item_name, $item, $subscription);
            // Create order line item on the renewal order
            $recurring_item_id = wc_add_order_item($new_order->id, array('order_item_name' => $item_name, 'order_item_type' => $item['type']));
            // Remove recurring line items and set item totals based on recurring line totals
            foreach ($item['item_meta'] as $meta_key => $meta_values) {
                foreach ($meta_values as $meta_value) {
                    wc_add_order_item_meta($recurring_item_id, $meta_key, maybe_unserialize($meta_value));
                }
            }
        }
        // If we got here, the subscription was created without problems
        $wpdb->query('COMMIT');
        return apply_filters('wcs_new_order_created', $new_order, $subscription);
    } catch (Exception $e) {
        // There was an error adding the subscription
        $wpdb->query('ROLLBACK');
        return new WP_Error('new-order-error', $e->getMessage());
    }
}
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:47,代码来源:wcs-order-functions.php


示例12: invokeGetReportRequestList

 function invokeGetReportRequestList(MarketplaceWebService_Interface $service, $request)
 {
     global $wpdb, $woocommerce;
     try {
         $response = $service->getReportRequestList($request);
         if ($response->isSetGetReportRequestListResult()) {
             $getReportRequestListResult = $response->getGetReportRequestListResult();
             $reportRequestInfoList = $getReportRequestListResult->getReportRequestInfoList();
             print_r($reportRequestInfoList);
             foreach ($reportRequestInfoList as $reportRequestInfo) {
                 if ($reportRequestInfo->isSetReportType() && $reportRequestInfo->getReportType() == '_GET_ORDERS_DATA_' && ($reportRequestInfo->isSetReportProcessingStatus() && $reportRequestInfo->getReportProcessingStatus() == '_DONE_')) {
                     if ($reportRequestInfo->isSetReportRequestId()) {
                         $ReportRequestId = $reportRequestInfo->getReportRequestId();
                     }
                     if ($reportRequestInfo->isSetGeneratedReportId()) {
                         $GeneratedReportId = $reportRequestInfo->getGeneratedReportId();
                         if ($GeneratedReportId == '' && $ReportRequestId != '') {
                             $GeneratedReportId = $this->get_report_list_api($ReportRequestId);
                             $data = $this->get_report_api($GeneratedReportId);
                         } else {
                             $data = $this->get_report_api($GeneratedReportId);
                         }
                         $xml = simplexml_load_string($data);
                         // Check and dump MWS Report API Response
                         $pwacheckkout = new Pwacheckout();
                         if ($pwacheckkout->get_option('mws_report_dump') == 'yes') {
                             $dir = $pwacheckkout->get_option('mws_report_dump_url');
                             if (!file_exists($dir) && !is_dir($dir)) {
                                 mkdir($dir, 0777);
                             }
                             $filename = $dir . $GeneratedReportId . '_mws_report';
                             $myfile = fopen($filename, "w");
                             fwrite($myfile, $data);
                             fclose($myfile);
                         }
                         foreach ($xml->Message as $orderdetail) {
                             $AmazonOrderID = (string) $orderdetail->OrderReport->AmazonOrderID;
                             $order_postmeta = $wpdb->get_results("select post_id from {$wpdb->postmeta} where meta_key = '_pwa_order_id' and meta_value = '{$AmazonOrderID}' ");
                             if (empty($order_postmeta)) {
                                 $order = wc_create_order();
                                 add_post_meta($order->id, '_pwa_order_id', $AmazonOrderID);
                                 $this->update_order_detail($order->id, $orderdetail);
                             } else {
                                 $order_id = $order_postmeta[0]->post_id;
                                 $this->update_order_detail($order_id, $orderdetail);
                             }
                         }
                     }
                 }
             }
             $dateTime = new DateTime('now', new DateTimeZone('UTC'));
             $time = $dateTime->format(DATE_ISO8601);
             $wpdb->insert($wpdb->prefix . 'pwa_mws_report_cron', array('created_before' => $time));
         }
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Report API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $this->generate_log($param);
     }
 }
开发者ID:booklein,项目名称:wpbookle,代码行数:63,代码来源:GetReportRequestList.php


示例13: hocwp_wc_insert_order

function hocwp_wc_insert_order($data)
{
    $post_id = hocwp_get_value_by_key($data, 'post_id');
    if (hocwp_id_number_valid($post_id)) {
        $post = get_post($post_id);
        if (is_a($post, 'WP_Post') && 'product' == $post->post_type) {
            $product = wc_get_product($post_id);
            $variable_product = new WC_Product_Variable($product);
            $variations = $variable_product->get_available_variations();
            $variation_args = array();
            $variation_id = null;
            foreach ($variations as $variation) {
                $variation_id = $variation['variation_id'];
                $variation_args['variation'] = $variation['attributes'];
            }
            $name = hocwp_get_value_by_key($data, 'name');
            $phone = hocwp_get_value_by_key($data, 'phone');
            $email = hocwp_get_value_by_key($data, 'email');
            $address = hocwp_get_value_by_key($data, 'address');
            $message = hocwp_get_value_by_key($data, 'message');
            $name = hocwp_sanitize_first_and_last_name($name);
            $attributes = hocwp_get_value_by_key($data, 'attributes');
            $addresses = array('first_name' => $name['first_name'], 'last_name' => $name['last_name'], 'email' => $email, 'phone' => $phone, 'address_1' => $address);
            $args = array('customer_note' => $message, 'created_via' => 'programmatically');
            if (is_user_logged_in()) {
                $current = wp_get_current_user();
                $args['customer_id'] = $current->ID;
            }
            $order = wc_create_order($args);
            $gateway = WC_Payment_Gateways::instance();
            $gateways = $gateway->get_available_payment_gateways();
            if (hocwp_array_has_value($gateways)) {
                $gateway = current($gateways);
                $order->set_payment_method($gateway);
            }
            $order->set_address($addresses);
            $order->set_address($addresses, 'shipping');
            if (hocwp_array_has_value($attributes) && hocwp_id_number_valid($variation_id)) {
                foreach ($attributes as $attribute) {
                    $attribute_name = hocwp_get_value_by_key($attribute, 'name');
                    $attribute_value = hocwp_get_value_by_key($attribute, 'value');
                    if (!empty($attribute_name) && !empty($attribute_value)) {
                        if (isset($variation_args['variation'][$attribute_name])) {
                            $variation_args['variation'][$attribute_name] = $attribute_value;
                        }
                    }
                }
                $variation_product = new WC_Product_Variation($variation_id);
                $order->add_product($variation_product, 1, $variation_args);
            } else {
                $order->add_product($product);
            }
            $order->record_product_sales();
            $order->calculate_totals();
            $order->payment_complete();
            return $order;
        }
    }
    return false;
}
开发者ID:skylarkcob,项目名称:hocwp-projects,代码行数:60,代码来源:woocommerce.php


示例14: create_order

 public function create_order()
 {
     var_dump($_POST);
     DABBA_API_Catch_Request::get()->check_params(array('company', 'phone', 'address_1', 'address_2', 'corp', 'timeframe', 'food_delivery_accepted', 'line_items', 'method_id', 'method_title', 'paid', 'user_id'));
     //$user = wp_get_current_user();
     $user = get_userdata($_POST['user_id']);
     $address = array('first_name' => $user->user_firstname, 'last_name' => $user->user_lastname, 'company' => $_POST['company'], 'email' => $user->user_email, 'phone' => $_POST['phone'], 'address_1' => $_POST['address_1'], 'address_2' => $_POST['address_2'], 'city' => 'Mexico City', 'state' => 'Distrito Federal', 'country' => 'MX', 'postcode' => $_POST['postcode']);
     $order = wc_create_order();
     $order->set_address($address, 'billing');
     $order->set_address($address, 'shipping');
     //$order->add_coupon('Fresher','10','2'); // accepted param $couponcode, $couponamount,$coupon_tax
     update_post_meta($order->id, 'billing_corp', sanitize_text_field($_POST['corp']));
     update_post_meta($order->id, 'billing_timeframe', sanitize_text_field($_POST['timeframe']));
     update_post_meta($order->id, 'billing_food_delivery_accepted', $_POST['food_delivery_accepted']);
     update_post_meta($order->id, '_payment_method', $_POST['method_id']);
     update_post_meta($order->id, '_payment_method_title', $_POST['method_title']);
     if (isset($_POST['stripe_transaction_id']) && isset($_POST['stripe_customer_id'])) {
         // $fee = ( 3.6 * $amount + 3 ) * 0.16;
         // $net_revenue = $amount - $fee;
         update_post_meta($order->id, 'Stripe Fee', 0);
         update_post_meta($order->id, 'Net Revenue From Stripe', 0);
         update_post_meta($order->id, '_transaction_id', $_POST['stripe_transaction_id']);
         update_post_meta($order->id, '_stripe_customer_id', $_POST['stripe_customer_id']);
         update_post_meta($order->id, '_stripe_charge_id', $_POST['stripe_transaction_id']);
     }
     if (isset($_POST['paypal_address']) && isset($_POST['paypal_payment_type']) && isset($_POST['paypal_transaction_fee'])) {
     }
     update_post_meta($order->id, '_customer_user', $_POST['user_id']);
     $line_items_decode = json_decode(stripslashes($_POST['line_items']));
     //$line_items_decode = json_decode( '[{"id" : "9579","quantity" : "1"},{"id" : "2933","quantity" :"1"}]');
     foreach ($line_items_decode as $item) {
         $order->add_product(get_product($item->id), $item->quantity);
     }
     if (isset($_POST['line_coupons'])) {
         $line_coupons_decode = json_decode(stripslashes($_POST['line_coupons']));
         foreach ($line_coupons_decode as $coupon) {
             $c = $order->add_coupon($coupon->code, $coupon->discount);
         }
     }
     if (isset($_POST['order_note'])) {
         $order->add_order_note($_POST['order_note']);
     }
     $order->calculate_totals();
     $order->reduce_order_stock();
     $order->update_status('processing');
     $data = array($order);
     DABBA_API_Output::get()->output(true, 200, '', $data);
 }
开发者ID:pcuervo,项目名称:dabba,代码行数:48,代码来源:class-dabba_api-webservices.php


示例15: create_postsale_order

 /**
  * Creates a postsale order with postsale item
  *
  * @param $original_order_id
  *
  * @return WC_Order
  */
 protected function create_postsale_order($original_order_id)
 {
     $original_order = wc_get_order($original_order_id);
     $postsale_product = $this->get_postsale_item();
     $product_order_price = get_option('wc_settings_tab_luup_price') ? get_option('wc_settings_tab_luup_price') : $postsale_product->get_regular_price();
     $order_qty = 1;
     $order_total = $product_order_price * $order_qty;
     $order_args = array('status' => '', 'customer_id' => get_current_user_id(), 'customer_note' => null, 'order_id' => 0, 'created_via' => '', 'parent' => 0);
     $order = wc_create_order($order_args);
     $order->add_product($postsale_product, $order_qty);
     $order->set_address($original_order->get_address('billing'), 'billing');
     $order->set_address($original_order->get_address('shipping'), 'shipping');
     $order->set_total($order_total);
     $order->add_order_note('Upsell order');
     $order->set_payment_method($this);
     return $order;
 }
开发者ID:LUUP-payments,项目名称:woocommerce-luup,代码行数:24,代码来源:class-wc-luup-copyandpay.php


示例16: wc1c_replace_document

function wc1c_replace_document($document)
{
    global $wpdb;
    if ($document['ХозОперация'] != "Заказ товара" || $document['Роль'] != "Продавец") {
        return;
    }
    $order = wc_get_order($document['Номер']);
    if (!$order) {
        $args = array('status' => 'on-hold', 'customer_note' => @$document['Комментарий']);
        $contragent_name = @$document['Контрагенты'][0]['Наименование'];
        if ($contragent_name == "Гость") {
            $user_id = 0;
        } elseif (strpos($contragent_name, ' ') !== false) {
            list($first_name, $last_name) = explode(' ', $contragent_name, 2);
            $result = $wpdb->get_var($wpdb->prepare("SELECT u1.user_id FROM {$wpdb->usermeta} u1 JOIN {$wpdb->usermeta} u2 ON u1.user_id = u2.user_id WHERE (u1.meta_key = 'billing_first_name' AND u1.meta_value = %s AND u2.meta_key = 'billing_last_na 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wc_create_page函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_create_new_customer函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap