当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_delete_order_item函数代码示例

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


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

示例1: order_delete_items

 function order_delete_items()
 {
     if (!wp_verify_nonce($_REQUEST['wcml_nonce'], 'order_delete_items')) {
         echo json_encode(array('error' => __('Invalid nonce', 'wpml-wcml')));
         die;
     }
     if (isset($_POST['order_id'])) {
         global $wpdb;
         $items = $wpdb->get_results($wpdb->prepare("SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = '%d'", $_POST['order_id']));
         foreach ($items as $item) {
             wc_delete_order_item(absint($item->order_item_id));
         }
     }
 }
开发者ID:sergioblanco86,项目名称:git-gitlab.com-kinivo-kinivo.com,代码行数:14,代码来源:multi-currency.class.php

示例2: update_order

 /**
  * Update order.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @param WP_Post $post Post data.
  * @return int|WP_Error
  */
 protected function update_order($request, $post)
 {
     try {
         $update_totals = false;
         $order = wc_get_order($post);
         $order_args = array('order_id' => $order->id);
         // Customer note.
         if (isset($request['customer_note'])) {
             $order_args['customer_note'] = $request['customer_note'];
         }
         // Customer ID.
         if (isset($request['customer_id']) && $request['customer_id'] != $order->get_user_id()) {
             // Make sure customer exists.
             if (false === get_user_by('id', $request['customer_id'])) {
                 throw new WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400);
             }
             update_post_meta($order->id, '_customer_user', $request['customer_id']);
         }
         // Update addresses.
         if (is_array($request['billing'])) {
             $this->update_address($order, $request['billing'], 'billing');
         }
         if (is_array($request['shipping'])) {
             $this->update_address($order, $request['shipping'], 'shipping');
         }
         $lines = array('line_item' => 'line_items', 'shipping' => 'shipping_lines', 'fee' => 'fee_lines', 'coupon' => 'coupon_lines');
         foreach ($lines as $line_type => $line) {
             if (isset($request[$line]) && is_array($request[$line])) {
                 $update_totals = true;
                 foreach ($request[$line] as $item) {
                     // Item ID is always required.
                     if (!array_key_exists('id', $item)) {
                         throw new WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID is required.', 'woocommerce'), 400);
                     }
                     // Create item.
                     if (is_null($item['id'])) {
                         $this->set_item($order, $line_type, $item, 'create');
                     } elseif ($this->item_is_null($item)) {
                         // Delete item.
                         wc_delete_order_item($item['id']);
                     } else {
                         // Update item.
                         $this->set_item($order, $line_type, $item, 'update');
                     }
                 }
             }
         }
         // Set payment method.
         if (!empty($request['payment_method'])) {
             update_post_meta($order->id, '_payment_method', $request['payment_method']);
         }
         if (!empty($request['payment_method_title'])) {
             update_post_meta($order->id, '_payment_method_title', $request['payment_method']);
         }
         if ($order->needs_payment() && isset($request['set_paid']) && true === $request['set_paid']) {
             $order->payment_complete(!empty($request['transaction_id']) ? $request['transaction_id'] : '');
         }
         // Set order currency.
         if (isset($request['currency'])) {
             update_post_meta($order->id, '_order_currency', $request['currency']);
         }
         // If items have changed, recalculate order totals.
         if ($update_totals) {
             $order->calculate_totals();
         }
         // Update meta data.
         if (!empty($request['meta_data']) && is_array($request['meta_data'])) {
             $this->update_meta_data($order->id, $request['meta_data']);
         }
         // Update the order post to set customer note/modified date.
         wc_update_order($order_args);
         // Order status.
         if (!empty($request['status'])) {
             $order->update_status($request['status'], isset($request['status_note']) ? $request['status_note'] : '');
         }
         return $order->id;
     } catch (WC_REST_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:coderkevin,项目名称:woocommerce,代码行数:87,代码来源:class-wc-rest-orders-controller.php

示例3: remove_order_item

 /**
  * Remove an order item
  */
 public function remove_order_item()
 {
     global $wpdb;
     check_ajax_referer('order-item', 'security');
     $order_item_ids = $_POST['order_item_ids'];
     if (sizeof($order_item_ids) > 0) {
         foreach ($order_item_ids as $id) {
             wc_delete_order_item(absint($id));
         }
     }
     die;
 }
开发者ID:chhavinav,项目名称:fr.ilovejuice,代码行数:15,代码来源:class-wc-ajax.php

示例4: remove_order_tax

 /**
  * Remove an order tax
  */
 public static function remove_order_tax()
 {
     check_ajax_referer('order-item', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     $order_id = absint($_POST['order_id']);
     $rate_id = absint($_POST['rate_id']);
     wc_delete_order_item($rate_id);
     // Return HTML items
     $order = wc_get_order($order_id);
     $data = get_post_meta($order_id);
     include 'admin/meta-boxes/views/html-order-items.php';
     die;
 }
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:18,代码来源:class-wc-ajax.php

示例5: woocommerce_delete_order_item

/**
 * @deprecated
 */
function woocommerce_delete_order_item($item_id)
{
    return wc_delete_order_item($item_id);
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:7,代码来源:wc-deprecated-functions.php

示例6: edit_order

 /**
  * Edit an order
  *
  * @since 2.2
  * @param int $id the order ID
  * @param array $data
  * @return array
  */
 public function edit_order($id, $data)
 {
     try {
         if (!isset($data['order'])) {
             throw new WC_API_Exception('woocommerce_api_missing_order_data', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'order'), 400);
         }
         $data = $data['order'];
         $update_totals = false;
         $id = $this->validate_request($id, $this->post_type, 'edit');
         if (is_wp_error($id)) {
             return $id;
         }
         $data = apply_filters('woocommerce_api_edit_order_data', $data, $id, $this);
         $order = wc_get_order($id);
         if (empty($order)) {
             throw new WC_API_Exception('woocommerce_api_invalid_order_id', __('Order ID is invalid', 'woocommerce'), 400);
         }
         $order_args = array('order_id' => $order->get_id());
         // Customer note.
         if (isset($data['note'])) {
             $order_args['customer_note'] = $data['note'];
         }
         // Customer ID.
         if (isset($data['customer_id']) && $data['customer_id'] != $order->get_user_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);
             }
             update_post_meta($order->get_id(), '_customer_user', $data['customer_id']);
         }
         // Billing/shipping address.
         $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])) {
                 $update_totals = true;
                 foreach ($data[$line] as $item) {
                     // Item ID is always required.
                     if (!array_key_exists('id', $item)) {
                         $item['id'] = null;
                     }
                     // Create item.
                     if (is_null($item['id'])) {
                         $this->set_item($order, $line_type, $item, 'create');
                     } elseif ($this->item_is_null($item)) {
                         // Delete item.
                         wc_delete_order_item($item['id']);
                     } else {
                         // Update item.
                         $this->set_item($order, $line_type, $item, 'update');
                     }
                 }
             }
         }
         // Payment method (and payment_complete() if `paid` == true and order needs payment).
         if (isset($data['payment_details']) && is_array($data['payment_details'])) {
             // Method ID.
             if (isset($data['payment_details']['method_id'])) {
                 update_post_meta($order->get_id(), '_payment_method', $data['payment_details']['method_id']);
             }
             // Method title.
             if (isset($data['payment_details']['method_title'])) {
                 update_post_meta($order->get_id(), '_payment_method_title', $data['payment_details']['method_title']);
             }
             // Mark as paid if set.
             if ($order->needs_payment() && 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->get_id(), '_order_currency', $data['currency']);
         }
         // If items have changed, recalculate order totals.
         if ($update_totals) {
             $order->calculate_totals();
         }
         // Update order meta.
         if (isset($data['order_meta']) && is_array($data['order_meta'])) {
             $this->set_order_meta($order->get_id(), $data['order_meta']);
         }
         // Update the order post to set customer note/modified date.
         wc_update_order($order_args);
         // Order status.
         if (!empty($data['status'])) {
             $order->update_status($data['status'], isset($data['status_note']) ? $data['status_note'] : '', true);
         }
         wc_delete_shop_order_transients($order->get_id());
         do_action('woocommerce_api_edit_order', $order->get_id(), $data, $this);
//.........这里部分代码省略.........
开发者ID:nishitlangaliya,项目名称:woocommerce,代码行数:101,代码来源:class-wc-api-orders.php

示例7: remove_order_tax

 /**
  * Remove an order tax
  */
 public static function remove_order_tax()
 {
     check_ajax_referer('order-item', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     $order_id = absint($_POST['order_id']);
     if (!wp_get_post_parent_id($order_id)) {
         $rate_id = absint($_POST['rate_id']);
         $parent_order = wc_get_order($order_id);
         $parent_taxes = $parent_order->get_taxes();
         $suborder_ids = self::get_suborder($order_id);
         $parent_tax_to_remove = $parent_taxes[$rate_id];
         foreach ($suborder_ids as $suborder_id) {
             $suborder = wc_get_order($suborder_id);
             $suborder_taxes = $suborder->get_taxes();
             foreach ($suborder_taxes as $suborder_tax_key => $suborder_tax_item) {
                 $suborder_tax_item['rate_id'] == $parent_tax_to_remove['rate_id'] && $suborder_tax_item['name'] == $parent_tax_to_remove['name'] && $suborder_tax_item['label'] == $parent_tax_to_remove['label'] && wc_delete_order_item($suborder_tax_key);
             }
         }
     } else {
         //is suborder
         //TODO: Suborder sub-routine
     }
 }
开发者ID:k2jysy,项目名称:mergeshop,代码行数:28,代码来源:class.yith-orders.php

示例8: save


//.........这里部分代码省略.........
                         $code = '';
                         $label = WC()->countries->tax_or_vat();
                     }
                     // Add line item
                     $new_id = wc_add_order_item($post_id, array('order_item_name' => wc_clean($code), 'order_item_type' => 'tax'));
                     // Add line item meta
                     if ($new_id) {
                         wc_update_order_item_meta($new_id, 'rate_id', $rate_id);
                         wc_update_order_item_meta($new_id, 'label', $label);
                         wc_update_order_item_meta($new_id, 'compound', $compound);
                         if (isset($order_taxes_amount[$item_id][$new_key])) {
                             wc_update_order_item_meta($new_id, 'tax_amount', wc_format_decimal($order_taxes_amount[$item_id][$new_key]));
                             $total_tax += wc_format_decimal($order_taxes_amount[$item_id][$new_key]);
                         }
                         if (isset($order_taxes_shipping_amount[$item_id][$new_key])) {
                             wc_update_order_item_meta($new_id, 'shipping_tax_amount', wc_format_decimal($order_taxes_shipping_amount[$item_id][$new_key]));
                             $total_shipping_tax += wc_format_decimal($order_taxes_shipping_amount[$item_id][$new_key]);
                         }
                     }
                 }
             } else {
                 $item_id = absint($item_id);
                 $rate_id = absint($order_taxes_rate_id[$item_id]);
                 if ($rate_id) {
                     $rate = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id));
                     $label = $rate->tax_rate_name ? $rate->tax_rate_name : WC()->countries->tax_or_vat();
                     $compound = $rate->tax_rate_compound ? 1 : 0;
                     $code = array();
                     $code[] = $rate->tax_rate_country;
                     $code[] = $rate->tax_rate_state;
                     $code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
                     $code[] = absint($rate->tax_rate_priority);
                     $code = strtoupper(implode('-', array_filter($code)));
                 } else {
                     $code = '';
                     $label = WC()->countries->tax_or_vat();
                 }
                 $wpdb->update($wpdb->prefix . "woocommerce_order_items", array('order_item_name' => wc_clean($code)), array('order_item_id' => $item_id), array('%s'), array('%d'));
                 wc_update_order_item_meta($item_id, 'rate_id', $rate_id);
                 wc_update_order_item_meta($item_id, 'label', $label);
                 wc_update_order_item_meta($item_id, 'compound', $compound);
                 if (isset($order_taxes_amount[$item_id])) {
                     wc_update_order_item_meta($item_id, 'tax_amount', wc_format_decimal($order_taxes_amount[$item_id]));
                     $total_tax += wc_format_decimal($order_taxes_amount[$item_id]);
                 }
                 if (isset($order_taxes_shipping_amount[$item_id])) {
                     wc_update_order_item_meta($item_id, 'shipping_tax_amount', wc_format_decimal($order_taxes_shipping_amount[$item_id]));
                     $total_shipping_tax += wc_format_decimal($order_taxes_shipping_amount[$item_id]);
                 }
             }
         }
     }
     // Update totals
     update_post_meta($post_id, '_order_tax', wc_format_decimal($total_tax));
     update_post_meta($post_id, '_order_shipping_tax', wc_format_decimal($total_shipping_tax));
     update_post_meta($post_id, '_order_discount', wc_format_decimal($_POST['_order_discount']));
     update_post_meta($post_id, '_order_total', wc_format_decimal($_POST['_order_total']));
     // Shipping Rows
     $order_shipping = 0;
     if (isset($_POST['shipping_method_id'])) {
         $get_values = array('shipping_method_id', 'shipping_method_title', 'shipping_method', 'shipping_cost');
         foreach ($get_values as $value) {
             ${$value} = isset($_POST[$value]) ? $_POST[$value] : array();
         }
         foreach ($shipping_method_id as $item_id => $value) {
             if ($item_id == 'new') {
                 foreach ($value as $new_key => $new_value) {
                     $method_id = wc_clean($shipping_method[$item_id][$new_key]);
                     $method_title = wc_clean($shipping_method_title[$item_id][$new_key]);
                     $cost = wc_format_decimal($shipping_cost[$item_id][$new_key]);
                     $new_id = wc_add_order_item($post_id, array('order_item_name' => $method_title, 'order_item_type' => 'shipping'));
                     if ($new_id) {
                         wc_add_order_item_meta($new_id, 'method_id', $method_id);
                         wc_add_order_item_meta($new_id, 'cost', $cost);
                     }
                     $order_shipping += $cost;
                 }
             } else {
                 $item_id = absint($item_id);
                 $method_id = wc_clean($shipping_method[$item_id]);
                 $method_title = wc_clean($shipping_method_title[$item_id]);
                 $cost = wc_format_decimal($shipping_cost[$item_id]);
                 $wpdb->update($wpdb->prefix . "woocommerce_order_items", array('order_item_name' => $method_title), array('order_item_id' => $item_id), array('%s'), array('%d'));
                 wc_update_order_item_meta($item_id, 'method_id', $method_id);
                 wc_update_order_item_meta($item_id, 'cost', $cost);
                 $order_shipping += $cost;
             }
         }
     }
     // Delete rows
     if (isset($_POST['delete_order_item_id'])) {
         $delete_ids = $_POST['delete_order_item_id'];
         foreach ($delete_ids as $id) {
             wc_delete_order_item(absint($id));
         }
     }
     delete_post_meta($post_id, '_shipping_method');
     delete_post_meta($post_id, '_shipping_method_title');
     update_post_meta($post_id, '_order_shipping', $order_shipping);
 }
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:101,代码来源:class-wc-meta-box-order-totals.php

示例9: update

 /**
  * Update an order.
  *
  * ## OPTIONS
  *
  * <id>
  * : Product ID
  *
  * [--<field>=<value>]
  * : One or more fields to update.
  *
  * ## AVAILABLE FIELDS
  *
  * For available fields, see: wp wc order create --help
  *
  * ## EXAMPLES
  *
  *    wp wc order update 123 --status=completed
  *
  * @todo  gedex
  * @since 2.5.0
  */
 public function update($args, $assoc_args)
 {
     try {
         $id = $args[0];
         $data = apply_filters('woocommerce_cli_update_order_data', $this->unflatten_array($assoc_args));
         $update_totals = false;
         $order = wc_get_order($id);
         if (empty($order)) {
             throw new WC_CLI_Exception('woocommerce_cli_invalid_order_id', __('Order ID is invalid', 'woocommerce'));
         }
         $order_args = array('order_id' => $order->id);
         // customer note
         if (isset($data['note'])) {
             $order_args['customer_note'] = $data['note'];
         }
         // order status
         if (!empty($data['status'])) {
             $order->update_status($data['status'], isset($data['status_note']) ? $data['status_note'] : '');
         }
         // customer ID
         if (isset($data['customer_id']) && $data['customer_id'] != $order->get_user_id()) {
             // make sure customer exists
             if (false === get_user_by('id', $data['customer_id'])) {
                 throw new WC_CLI_Exception('woocommerce_cli_invalid_customer_id', __('Customer ID is invalid', 'woocommerce'));
             }
             update_post_meta($order->id, '_customer_user', $data['customer_id']);
         }
         // billing/shipping address
         $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])) {
                 $update_totals = true;
                 foreach ($data[$line] as $item) {
                     // item ID is always required
                     if (!array_key_exists('id', $item)) {
                         throw new WC_CLI_Exception('woocommerce_invalid_item_id', __('Order item ID is required', 'woocommerce'));
                     }
                     // create item
                     if (is_null($item['id'])) {
                         $this->set_item($order, $line_type, $item, 'create');
                     } elseif ($this->item_is_null($item)) {
                         // delete item
                         wc_delete_order_item($item['id']);
                     } else {
                         // update item
                         $this->set_item($order, $line_type, $item, 'update');
                     }
                 }
             }
         }
         // payment method (and payment_complete() if `paid` == true and order needs payment)
         if (isset($data['payment_details']) && is_array($data['payment_details'])) {
             // method ID
             if (isset($data['payment_details']['method_id'])) {
                 update_post_meta($order->id, '_payment_method', $data['payment_details']['method_id']);
             }
             // method title
             if (isset($data['payment_details']['method_title'])) {
                 update_post_meta($order->id, '_payment_method_title', $data['payment_details']['method_title']);
             }
             // mark as paid if set
             if ($order->needs_payment() && isset($data['payment_details']['paid']) && $this->is_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_CLI_Exception('woocommerce_invalid_order_currency', __('Provided order currency is invalid', 'woocommerce'));
             }
             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']);
         }
         // if items have changed, recalculate order totals
//.........这里部分代码省略.........
开发者ID:jgcopple,项目名称:drgaryschwantz,代码行数:101,代码来源:class-wc-cli-order.php

示例10: delete_order_items

 /**
  * Delete all order items
  * @param $order_id
  */
 private function delete_order_items($order_id)
 {
     global $wpdb;
     $order_item_ids = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT      order_item_id\n\t\t\tFROM        {$wpdb->prefix}woocommerce_order_items\n\t\t\tWHERE       order_id = %d\n\t\t", $order_id));
     foreach ($order_item_ids as $item_id) {
         wc_delete_order_item($item_id);
     }
 }
开发者ID:rpidanny,项目名称:WooCommerce-POS,代码行数:12,代码来源:class-wc-pos-orders.php

示例11: remove_order_tax

 /**
  * Remove an order tax
  */
 public static function remove_order_tax()
 {
     check_ajax_referer('order-item', 'security');
     $order_id = absint($_POST['order_id']);
     $rate_id = absint($_POST['rate_id']);
     wc_delete_order_item($rate_id);
     // Return HTML items
     $order = new WC_Order($order_id);
     $data = get_post_meta($order_id);
     include 'admin/meta-boxes/views/html-order-items.php';
     die;
 }
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:15,代码来源:class-wc-ajax.php

示例12: remove_cancelled_booking

 /**
  * Removes the booking from an order
  * when the order includes only bookings which require confirmation
  *
  * @param int $booking_id
  */
 public function remove_cancelled_booking($booking_id)
 {
     global $wpdb;
     $booking = get_wc_booking($booking_id);
     $order = $booking->get_order();
     $bookings = array();
     foreach ($order->get_items() as $order_item_id => $item) {
         if ($item[__('Booking ID', 'woocommerce-bookings')] == $booking_id) {
             wc_delete_order_item($order_item_id);
             $order->calculate_totals();
             $order->add_order_note(sprintf(__('The product %s has been removed from the order because the booking #%d cannot be confirmed.', 'woocommerce-bookings'), $item['name'], $booking_id), true);
         }
     }
 }
开发者ID:baperrou,项目名称:pedal-bookings,代码行数:20,代码来源:class-wc-booking-order-manager.php

示例13: remove_duplicate_renewal_taxes

 /**
  * Remove duplicate tax column from renewal orders
  *
  * @since 4.2
  */
 public function remove_duplicate_renewal_taxes($renewal_order, $original_order)
 {
     global $wpdb;
     $original_taxes = $original_order->get_items('recurring_tax');
     $new_taxes = $renewal_order->get_taxes();
     $to_remove = array();
     foreach ($original_taxes as $tax_item_id => $data) {
         if ($data['rate_id'] != WT_RATE_ID) {
             continue;
         }
         foreach ($new_taxes as $tax_id => $tax_data) {
             if ($tax_data['tax_amount'] == $data['tax_amount'] && $tax_data['rate_id'] == $data['rate_id']) {
                 $to_remove[] = $tax_id;
             }
         }
     }
     foreach ($to_remove as $tax_item_id) {
         wc_delete_order_item($tax_item_id);
     }
 }
开发者ID:sergioblanco86,项目名称:git-gitlab.com-kinivo-kinivo.com,代码行数:25,代码来源:class-wc-wootax-subscriptions.php

示例14: add_order_meta

 /**
  * When a new order is inserted, add subscriptions related order meta.
  *
  * @since 1.0
  */
 public static function add_order_meta($order_id, $posted)
 {
     global $woocommerce;
     if (!WC_Subscriptions_Cart::cart_contains_subscription_renewal('child') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
         // This works because the 'woocommerce_add_order_item_meta' runs before the 'woocommerce_checkout_update_order_meta' hook
         // Set the recurring totals so totals display correctly on order page
         update_post_meta($order_id, '_order_recurring_discount_cart', WC_Subscriptions_Cart::get_recurring_discount_cart());
         update_post_meta($order_id, '_order_recurring_discount_total', WC_Subscriptions_Cart::get_recurring_discount_total());
         update_post_meta($order_id, '_order_recurring_shipping_tax_total', WC_Subscriptions_Cart::get_recurring_shipping_tax_total());
         update_post_meta($order_id, '_order_recurring_shipping_total', WC_Subscriptions_Cart::get_recurring_shipping_total());
         update_post_meta($order_id, '_order_recurring_tax_total', WC_Subscriptions_Cart::get_recurring_total_tax());
         update_post_meta($order_id, '_order_recurring_total', WC_Subscriptions_Cart::get_recurring_total());
         // Set the recurring payment method - it starts out the same as the original by may change later
         update_post_meta($order_id, '_recurring_payment_method', get_post_meta($order_id, '_payment_method', true));
         update_post_meta($order_id, '_recurring_payment_method_title', get_post_meta($order_id, '_payment_method_title', true));
         $order = new WC_Order($order_id);
         $order_fees = $order->get_fees();
         // the fee order items have already been set, we just need to to add the recurring total meta
         $cart_fees = $woocommerce->cart->get_fees();
         foreach ($order->get_fees() as $item_id => $order_fee) {
             // Find the matching fee in the cart
             foreach ($cart_fees as $fee_index => $cart_fee) {
                 if (sanitize_title($order_fee['name']) == $cart_fee->id) {
                     woocommerce_add_order_item_meta($item_id, '_recurring_line_total', wc_format_decimal($cart_fee->recurring_amount));
                     woocommerce_add_order_item_meta($item_id, '_recurring_line_tax', wc_format_decimal($cart_fee->recurring_tax));
                     unset($cart_fees[$fee_index]);
                     break;
                 }
             }
         }
         // Get recurring taxes into same format as _order_taxes
         $order_recurring_taxes = array();
         foreach (WC_Subscriptions_Cart::get_recurring_taxes() as $tax_key => $tax_amount) {
             $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $woocommerce->cart->tax->get_rate_code($tax_key), 'order_item_type' => 'recurring_tax'));
             if ($item_id) {
                 wc_add_order_item_meta($item_id, 'rate_id', $tax_key);
                 wc_add_order_item_meta($item_id, 'label', WC()->cart->tax->get_rate_label($tax_key));
                 wc_add_order_item_meta($item_id, 'compound', absint(WC()->cart->tax->is_compound($tax_key) ? 1 : 0));
                 wc_add_order_item_meta($item_id, 'tax_amount', wc_format_decimal(isset(WC()->cart->recurring_taxes[$tax_key]) ? WC()->cart->recurring_taxes[$tax_key] : 0));
                 wc_add_order_item_meta($item_id, 'shipping_tax_amount', wc_format_decimal(isset(WC()->cart->recurring_shipping_taxes[$tax_key]) ? WC()->cart->recurring_shipping_taxes[$tax_key] : 0));
             }
         }
         $payment_gateways = $woocommerce->payment_gateways->payment_gateways();
         if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
             update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
         } elseif (isset($payment_gateways[$posted['payment_method']]) && !$payment_gateways[$posted['payment_method']]->supports('subscriptions')) {
             update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
         }
         $cart_item = WC_Subscriptions_Cart::cart_contains_subscription_renewal();
         if (isset($cart_item['subscription_renewal']) && 'parent' == $cart_item['subscription_renewal']['role']) {
             update_post_meta($order_id, '_original_order', $cart_item['subscription_renewal']['original_order']);
         }
         // WC 2.1+
         if (!WC_Subscriptions::is_woocommerce_pre_2_1()) {
             // Recurring coupons
             if ($applied_coupons = $woocommerce->cart->get_coupons()) {
                 foreach ($applied_coupons as $code => $coupon) {
                     $item_id = woocommerce_get_order_item_meta($order_id, array('order_item_name' => $code, 'order_item_type' => 'coupon'));
                     // Add line item meta
                     if ($item_id) {
                         woocommerce_add_order_item_meta($item_id, 'recurring_discount_amount', isset($woocommerce->cart->recurring_coupon_discount_amounts[$code]) ? $woocommerce->cart->recurring_coupon_discount_amounts[$code] : 0);
                     }
                 }
             }
             // Add recurring shipping order items
             if (WC_Subscriptions_Cart::cart_contains_subscriptions_needing_shipping()) {
                 $packages = $woocommerce->shipping->get_packages();
                 $checkout = $woocommerce->checkout();
                 foreach ($packages as $i => $package) {
                     if (isset($package['rates'][$checkout->shipping_methods[$i]])) {
                         $method = $package['rates'][$checkout->shipping_methods[$i]];
                         $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $method->label, 'order_item_type' => 'recurring_shipping'));
                         if ($item_id) {
                             woocommerce_add_order_item_meta($item_id, 'method_id', $method->id);
                             woocommerce_add_order_item_meta($item_id, 'cost', WC_Subscriptions::format_total($method->cost));
                             do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $order_id, $item_id, $i);
                         }
                     }
                 }
             }
             // Remove shipping on original order if it was added but is not required
             if (!WC_Subscriptions_Cart::charge_shipping_up_front()) {
                 foreach ($order->get_shipping_methods() as $order_item_id => $shipping_method) {
                     wc_delete_order_item($order_item_id);
                 }
             }
         } else {
             update_post_meta($order_id, '_recurring_shipping_method', get_post_meta($order_id, '_shipping_method', true), true);
             update_post_meta($order_id, '_recurring_shipping_method_title', get_post_meta($order_id, '_shipping_method_title', true), true);
         }
     }
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:97,代码来源:class-wc-subscriptions-checkout.php

示例15: delete_removed_items

 /**
  * Delete items that were not present in updated CSV when merging
  *
  * @since 3.0.0
  * @param array $existing
  * @param array $updated
  */
 private function delete_removed_items($existing, $updated)
 {
     if (count($existing) != count($updated)) {
         // if this order item was not updated, it must be removed from the order
         foreach ($existing as $order_item_id => $item) {
             if (!in_array($order_item_id, $updated)) {
                 wc_delete_order_item($order_item_id);
             }
         }
     }
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:18,代码来源:class-wc-csv-import-suite-order-import.php


注:本文中的wc_delete_order_item函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。