當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。