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


PHP wc_save_order_items函数代码示例

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


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

示例1: save_order_items

 /**
  * Save order items via ajax
  */
 public static function save_order_items()
 {
     check_ajax_referer('order-item', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     if (isset($_POST['order_id']) && isset($_POST['items'])) {
         $order_id = absint($_POST['order_id']);
         // Parse the jQuery serialized items
         $items = array();
         parse_str($_POST['items'], $items);
         // Save order items
         wc_save_order_items($order_id, $items);
         // 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,代码行数:23,代码来源:class-wc-ajax.php

示例2: add_line_taxes


//.........这里部分代码省略.........
                 $item_tax_status = 'taxable';
             }
             if ('0' !== $order_item_tax_class[$item_id] && 'taxable' === $item_tax_status) {
                 $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $order_item_tax_class[$item_id]));
                 $line_taxes = WC_Tax::calc_tax($line_total[$item_id], $tax_rates, false);
                 $line_subtotal_taxes = WC_Tax::calc_tax($line_subtotal[$item_id], $tax_rates, false);
                 // Set the new line_tax
                 foreach ($line_taxes as $_tax_id => $_tax_value) {
                     $items['line_tax'][$item_id][$_tax_id] = $_tax_value;
                 }
                 // Set the new line_subtotal_tax
                 foreach ($line_subtotal_taxes as $_tax_id => $_tax_value) {
                     $items['line_subtotal_tax'][$item_id][$_tax_id] = $_tax_value;
                 }
                 // Sum the item taxes
                 foreach (array_keys($taxes + $line_taxes) as $key) {
                     $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
                 }
             }
         }
     }
     // Get shipping taxes
     if (isset($items['shipping_method_id'])) {
         $matched_tax_rates = array();
         $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => ''));
         if ($tax_rates) {
             foreach ($tax_rates as $key => $rate) {
                 if (isset($rate['shipping']) && 'yes' == $rate['shipping']) {
                     $matched_tax_rates[$key] = $rate;
                 }
             }
         }
         $shipping_cost = $shipping_taxes = array();
         foreach ($items['shipping_method_id'] as $item_id) {
             $item_id = absint($item_id);
             $shipping_cost[$item_id] = isset($items['shipping_cost'][$parent_item_id]) ? wc_format_decimal($items['shipping_cost'][$parent_item_id]) : 0;
             $_shipping_taxes = WC_Tax::calc_shipping_tax($shipping_cost[$item_id], $matched_tax_rates);
             // Set the new shipping_taxes
             foreach ($_shipping_taxes as $_tax_id => $_tax_value) {
                 $items['shipping_taxes'][$item_id][$_tax_id] = $_tax_value;
                 $shipping_taxes[$_tax_id] = isset($shipping_taxes[$_tax_id]) ? $shipping_taxes[$_tax_id] + $_tax_value : $_tax_value;
             }
         }
     }
     // Remove old tax rows
     $order->remove_order_items('tax');
     // Add tax rows
     foreach (array_keys($taxes + $shipping_taxes) as $tax_rate_id) {
         $order->add_tax($tax_rate_id, isset($taxes[$tax_rate_id]) ? $taxes[$tax_rate_id] : 0, isset($shipping_taxes[$tax_rate_id]) ? $shipping_taxes[$tax_rate_id] : 0);
     }
     // Create the new order_taxes
     foreach ($order->get_taxes() as $tax_id => $tax_item) {
         $items['order_taxes'][$tax_id] = absint($tax_item['rate_id']);
     }
     foreach ($items as $meta_key => $meta_values) {
         if (is_array($meta_values)) {
             foreach ($meta_values as $key => $meta_value) {
                 if ('order_taxes' == $meta_key) {
                     continue;
                 } else {
                     if ('order_item_id' == $meta_key) {
                         $child_item_id = self::get_child_item_id($meta_value);
                         if ($child_item_id) {
                             $items[$meta_key][$key] = $child_item_id;
                         } else {
                             unset($items[$meta_key][$key]);
                         }
                     } else {
                         if ('meta_key' == $meta_key || 'meta_value' == $meta_key) {
                             unset($items[$meta_key][$key]);
                         } else {
                             if ('line_tax' == $meta_key || 'line_subtotal_tax' == $meta_key || 'refund_line_tax' == $meta_key) {
                                 $line_tax_ids = $items[$meta_key];
                                 $child_item_ids = array_keys($order->get_items());
                                 foreach ($line_tax_ids as $line_tax_id => $line_tax_value) {
                                     if (!in_array($line_tax_id, $child_item_ids)) {
                                         unset($items[$meta_key][$line_tax_id]);
                                     }
                                 }
                             } else {
                                 $child_item_id = self::get_child_item_id($meta_value);
                                 if ($child_item_id) {
                                     $items[$meta_key][$child_item_id] = $items[$meta_key][$key];
                                     unset($items[$meta_key][$key]);
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ('_order_total' == $meta_key) {
                 $items['_order_total'] = $order->get_total();
             }
         }
     }
     if (!empty($items['order_item_id'])) {
         wc_save_order_items($order_id, $items);
     }
 }
开发者ID:k2jysy,项目名称:mergeshop,代码行数:101,代码来源:class.yith-orders.php

示例3: save

 /**
  * Save meta box data
  */
 public static function save($post_id, $post)
 {
     wc_save_order_items($post_id, $_POST);
 }
开发者ID:abcode619,项目名称:wpstuff,代码行数:7,代码来源:class-wc-meta-box-order-items.php

示例4: save

 /**
  * Save meta box data
  */
 public static function save($post_id, $post)
 {
     wc_save_order_items($post_id, $_POST);
     // tell plugins order items were saved
     do_action('woocommerce_saved_order_items', $post_id, $_POST);
 }
开发者ID:Jayriq,项目名称:opentickets-community,代码行数:9,代码来源:class-wc-meta-box-order-items.php

示例5: ajax_update_order_tax


//.........这里部分代码省略.........
                     // Fee
                     $tic = WT_FEE_TIC;
                     $cost = $items['line_total'][$item_id];
                     $type = 'fee';
                 }
             }
             // Calculate unit price
             $unit_price = $cost / $qty;
             // Add item to final items array
             if ($unit_price != 0) {
                 // Map item_id to item type
                 $type_array[$item_id] = $type == 'shipping' ? 'shipping' : 'cart';
                 // Add tax amount to tax array
                 $old_taxes[$item_id] = $order->get_item_tax($item_id);
                 // Add to items array
                 $item_data = array('Index' => '', 'ItemID' => $item_id, 'Qty' => $qty, 'Price' => $unit_price, 'Type' => $type);
                 if (!empty($tic) && $tic) {
                     $item_data['TIC'] = $tic;
                 }
                 $final_items[] = $item_data;
             }
         }
     }
     // Send lookup request using the generated items and mapping array
     $res = $order->do_lookup($final_items, $type_array);
     // Convert response array to be sent back to client
     // @see WC_AJAX::calc_line_taxes()
     if (is_array($res)) {
         if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
             if (!isset($items['line_tax'])) {
                 $items['line_tax'] = array();
             }
             if (!isset($items['line_subtotal_tax'])) {
                 $items['line_subtotal_tax'] = array();
             }
             $items['order_taxes'] = array();
             foreach ($res as $item) {
                 $id = $item->ItemID;
                 $tax = $item->TaxAmount;
                 if (is_array($items['shipping_method_id']) && in_array($id, $items['shipping_method_id'])) {
                     $items['shipping_taxes'][$id][WT_RATE_ID] = $tax;
                 } else {
                     $items['line_tax'][$id][WT_RATE_ID] = $tax;
                     $items['line_subtotal_tax'][$id][WT_RATE_ID] = $tax;
                 }
             }
             $items['order_taxes'][self::get_meta($order_id, 'tax_item_id')] = absint(WT_RATE_ID);
             wc_save_order_items($order_id, $items);
             // Return HTML items
             $data = get_post_meta($order_id);
             $order = $order->order;
             include ABSPATH . '/' . PLUGINDIR . '/woocommerce/includes/admin/meta-boxes/views/html-order-items.php';
             die;
         } else {
             if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) {
                 // We are going to send back a JSON response
                 header('Content-Type: application/json; charset=utf-8');
                 $item_tax = $shipping_tax = 0;
                 $tax_row_html = '';
                 $item_taxes = array();
                 // Update item taxes
                 foreach ($res as $item) {
                     $id = $item->ItemID;
                     $tax = $item->TaxAmount;
                     if ($id == WT_SHIPPING_ITEM) {
                         $shipping_tax += $tax;
                     } else {
                         $item_taxes[$id] = array('line_subtotal_tax' => wc_format_localized_price($tax), 'line_tax' => wc_format_localized_price($tax));
                         $item_tax += $tax;
                     }
                 }
                 // Fetch array mapping tax rate ids to tax codes
                 $tax_codes = array();
                 $taxes = $order->order->get_taxes();
                 foreach ($taxes as $item_id => $data) {
                     $code = array();
                     $rate_id = $data['rate_id'];
                     $rate_data = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = '{$rate_id}'");
                     $code[] = $rate_data->tax_rate_country;
                     $code[] = $rate_data->tax_rate_state;
                     $code[] = $rate_data->tax_rate_name ? sanitize_title($rate_data->tax_rate_name) : 'TAX';
                     $code[] = absint($rate_data->tax_rate_priority);
                     $tax_codes[$rate_id] = strtoupper(implode('-', array_filter($code)));
                 }
                 // Loop through tax items to build tax row HTML
                 ob_start();
                 foreach ($taxes as $item_id => $item) {
                     include ABSPATH . '/' . PLUGINDIR . '/woocommerce/includes/admin/post-types/meta-boxes/views/html-order-tax.php';
                 }
                 $tax_row_html = ob_get_clean();
                 // Return
                 echo json_encode(array('item_tax' => $item_tax, 'item_taxes' => $item_taxes, 'shipping_tax' => $shipping_tax, 'tax_row_html' => $tax_row_html));
                 // Quit out
                 die;
             }
         }
     } else {
         die(json_encode(array('status' => 'error', 'message' => $res)));
     }
 }
开发者ID:sergioblanco86,项目名称:git-gitlab.com-kinivo-kinivo.com,代码行数:101,代码来源:class-wt-orders.php

示例6: save_order_items

 /**
  * Save order items via ajax
  * exact copy from /wp-content/plugins/woocommerce/includes/class-wc-ajax.php, with change to template selection
  */
 public static function save_order_items()
 {
     check_ajax_referer('order-item', 'security');
     if (isset($_POST['order_id']) && isset($_POST['items'])) {
         $order_id = absint($_POST['order_id']);
         // Parse the jQuery serialized items
         $items = array();
         parse_str($_POST['items'], $items);
         // Save order items
         wc_save_order_items($order_id, $items);
         // Return HTML items
         $order = wc_get_order($order_id);
         $data = get_post_meta($order_id);
         //include( 'admin/meta-boxes/views/html-order-items.php' );
         //@@@@LOUSHOU - allow overtake of template
         include apply_filters('qsot-woo-template', 'meta-boxes/views/html-order-items.php', 'admin');
     }
     die;
 }
开发者ID:Jayriq,项目名称:opentickets-community,代码行数:23,代码来源:admin-ajax.class.php


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