本文整理汇总了PHP中wc_add_order_item函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_add_order_item函数的具体用法?PHP wc_add_order_item怎么用?PHP wc_add_order_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_add_order_item函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: add_order_item
/**
* Add order item via ajax
* exact copy from /wp-content/plugins/woocommerce/includes/class-wc-ajax.php, with change to template selection
*/
public static function add_order_item()
{
check_ajax_referer('order-item', 'security');
$item_to_add = sanitize_text_field($_POST['item_to_add']);
$order_id = absint($_POST['order_id']);
// Find the item
if (!is_numeric($item_to_add)) {
die;
}
$post = get_post($item_to_add);
if (!$post || 'product' !== $post->post_type && 'product_variation' !== $post->post_type) {
die;
}
$_product = wc_get_product($post->ID);
$order = wc_get_order($order_id);
$order_taxes = $order->get_taxes();
$class = 'new_row';
// Set values
$item = array();
$item['product_id'] = $_product->id;
$item['variation_id'] = isset($_product->variation_id) ? $_product->variation_id : '';
$item['variation_data'] = isset($_product->variation_data) ? $_product->variation_data : '';
$item['name'] = $_product->get_title();
$item['tax_class'] = $_product->get_tax_class();
$item['qty'] = 1;
$item['line_subtotal'] = wc_format_decimal($_product->get_price_excluding_tax());
$item['line_subtotal_tax'] = '';
$item['line_total'] = wc_format_decimal($_product->get_price_excluding_tax());
$item['line_tax'] = '';
// Add line item
$item_id = wc_add_order_item($order_id, array('order_item_name' => $item['name'], 'order_item_type' => 'line_item'));
// Add line item meta
if ($item_id) {
wc_add_order_item_meta($item_id, '_qty', $item['qty']);
wc_add_order_item_meta($item_id, '_tax_class', $item['tax_class']);
wc_add_order_item_meta($item_id, '_product_id', $item['product_id']);
wc_add_order_item_meta($item_id, '_variation_id', $item['variation_id']);
wc_add_order_item_meta($item_id, '_line_subtotal', $item['line_subtotal']);
wc_add_order_item_meta($item_id, '_line_subtotal_tax', $item['line_subtotal_tax']);
wc_add_order_item_meta($item_id, '_line_total', $item['line_total']);
wc_add_order_item_meta($item_id, '_line_tax', $item['line_tax']);
// Since 2.2
wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(), 'subtotal' => array()));
// Store variation data in meta
if ($item['variation_data'] && is_array($item['variation_data'])) {
foreach ($item['variation_data'] as $key => $value) {
wc_add_order_item_meta($item_id, str_replace('attribute_', '', $key), $value);
}
}
do_action('woocommerce_ajax_add_order_item_meta', $item_id, $item);
}
$item = apply_filters('woocommerce_ajax_order_item', $item, $item_id);
//include( 'admin/meta-boxes/views/html-order-item.php' );
//@@@@LOUSHOU - allow overtake of template
include apply_filters('qsot-woo-template', 'meta-boxes/views/html-order-item.php', 'admin');
// Quit out
die;
}
开发者ID:Jayriq,项目名称:opentickets-community,代码行数:62,代码来源:admin-ajax.class.php
示例2: add_product
/**
* Add the details of an order item to a subscription as a product line item.
*
* When adding a product to a subscription, we can't use WC_Abstract_Order::add_product() because it requires a product object
* and the details of the product may have changed since it was purchased so we can't simply instantiate an instance of the
* product based on ID.
*
* @param WC_Subscription $new_subscription A subscription object
* @param int $order_item_id ID of the subscription item on the original order
* @param array $order_item An array of order item data in the form returned by WC_Abstract_Order::get_items()
* @return int Subscription $item_id The order item id of the new line item added to the subscription.
* @since 2.0
*/
private static function add_product($new_subscription, $order_item_id, $order_item)
{
global $wpdb;
$item_id = wc_add_order_item($new_subscription->id, array('order_item_name' => $order_item['name'], 'order_item_type' => 'line_item'));
WCS_Upgrade_Logger::add(sprintf('For subscription %d: new line item ID %d added', $new_subscription->id, $item_id));
$order_item = WCS_Repair_2_0::maybe_repair_order_item($order_item);
$wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}woocommerce_order_itemmeta` (`order_item_id`, `meta_key`, `meta_value`)\n\t\t\t VALUES\n\t\t\t\t(%d, '_qty', %s),\n\t\t\t\t(%d, '_tax_class', %s),\n\t\t\t\t(%d, '_product_id', %s),\n\t\t\t\t(%d, '_variation_id', %s),\n\t\t\t\t(%d, '_line_subtotal', %s),\n\t\t\t\t(%d, '_line_total', %s),\n\t\t\t\t(%d, '_line_subtotal_tax', %s),\n\t\t\t\t(%d, '_line_tax', %s)", $item_id, $order_item['qty'], $item_id, $order_item['tax_class'], $item_id, $order_item['product_id'], $item_id, $order_item['variation_id'], $item_id, $order_item['recurring_line_subtotal'], $item_id, $order_item['recurring_line_total'], $item_id, $order_item['recurring_line_subtotal_tax'], $item_id, $order_item['recurring_line_tax']));
// Save tax data array added in WC 2.2 (so it won't exist for all orders/subscriptions)
self::add_line_tax_data($item_id, $order_item_id, $order_item);
if (isset($order_item['subscription_trial_length']) && $order_item['subscription_trial_length'] > 0) {
wc_add_order_item_meta($item_id, '_has_trial', 'true');
}
// Don't copy item meta already copied
$reserved_item_meta_keys = array('_item_meta', '_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_total', '_line_tax', '_line_tax_data', '_line_subtotal_tax');
$meta_keys_to_copy = array_diff(array_keys($order_item['item_meta']), array_merge($reserved_item_meta_keys, self::$subscription_item_meta_keys));
// Add variation and any other meta
foreach ($meta_keys_to_copy as $meta_key) {
foreach ($order_item['item_meta'][$meta_key] as $meta_value) {
wc_add_order_item_meta($item_id, $meta_key, $meta_value);
}
}
WCS_Upgrade_Logger::add(sprintf('For subscription %d: for item %d added %s', $new_subscription->id, $item_id, implode(', ', $meta_keys_to_copy)));
// Now that we've copied over the old data, prefix some the subscription meta keys with _wcs_migrated to deprecate it without deleting it (yet)
$rows_affected = self::deprecate_item_meta($order_item_id);
WCS_Upgrade_Logger::add(sprintf('For subscription %d: %s rows of line item meta deprecated', $new_subscription->id, $rows_affected));
return $item_id;
}
开发者ID:slavic18,项目名称:cats,代码行数:40,代码来源:class-wcs-upgrade-2-0.php
示例3: unset
$wpdb->query($wpdb->prepare("\n\t\t\t\tUPDATE {$wpdb->postmeta}\n\t\t\t\tSET meta_key = '_order_items_old'\n\t\t\t\tWHERE meta_key = '_order_items'\n\t\t\t\tAND post_id = %d\n\t\t\t", $order_item_row->post_id));
}
unset($meta_rows, $item_id, $order_item);
}
}
// Do the same kind of update for order_taxes - move to lines
// Reverse with UPDATE `wpwc_postmeta` SET meta_key = '_order_taxes' WHERE meta_key = '_order_taxes_old'
$order_tax_rows = $wpdb->get_results("\n\tSELECT * FROM {$wpdb->postmeta}\n\tWHERE meta_key = '_order_taxes'\n");
foreach ($order_tax_rows as $order_tax_row) {
$order_taxes = (array) maybe_unserialize($order_tax_row->meta_value);
if ($order_taxes) {
foreach ($order_taxes as $order_tax) {
if (!isset($order_tax['label']) || !isset($order_tax['cart_tax']) || !isset($order_tax['shipping_tax'])) {
continue;
}
$item_id = wc_add_order_item($order_tax_row->post_id, array('order_item_name' => $order_tax['label'], 'order_item_type' => 'tax'));
// Add line item meta
if ($item_id) {
wc_add_order_item_meta($item_id, 'compound', absint(isset($order_tax['compound']) ? $order_tax['compound'] : 0));
wc_add_order_item_meta($item_id, 'tax_amount', wc_clean($order_tax['cart_tax']));
wc_add_order_item_meta($item_id, 'shipping_tax_amount', wc_clean($order_tax['shipping_tax']));
}
// Delete from DB (rename)
$wpdb->query($wpdb->prepare("\n\t\t\t\tUPDATE {$wpdb->postmeta}\n\t\t\t\tSET meta_key = '_order_taxes_old'\n\t\t\t\tWHERE meta_key = '_order_taxes'\n\t\t\t\tAND post_id = %d\n\t\t\t", $order_tax_row->post_id));
unset($tax_amount);
}
}
}
// Grab the pre 2.0 Image options and use to populate the new image options settings,
// cleaning up afterwards like nice people do
foreach (array('catalog', 'single', 'thumbnail') as $value) {
开发者ID:prosenjit-itobuz,项目名称:nutraperfect,代码行数:31,代码来源:woocommerce-update-2.0.php
示例4: dokan_create_sub_order_shipping
/**
* Create shipping for a sub-order if neccessary
*
* @param WC_Order $parent_order
* @param int $order_id
* @param array $product_ids
* @return type
*/
function dokan_create_sub_order_shipping($parent_order, $order_id, $seller_products)
{
// take only the first shipping method
$shipping_methods = $parent_order->get_shipping_methods();
$shipping_method = is_array($shipping_methods) ? reset($shipping_methods) : array();
// bail out if no shipping methods found
if (!$shipping_method) {
return;
}
$shipping_products = array();
$packages = array();
// emulate shopping cart for calculating the shipping method
foreach ($seller_products as $product_item) {
$product = get_product($product_item['product_id']);
if ($product->needs_shipping()) {
$shipping_products[] = array('product_id' => $product_item['product_id'], 'variation_id' => $product_item['variation_id'], 'variation' => '', 'quantity' => $product_item['qty'], 'data' => $product, 'line_total' => $product_item['line_total'], 'line_tax' => $product_item['line_tax'], 'line_subtotal' => $product_item['line_subtotal'], 'line_subtotal_tax' => $product_item['line_subtotal_tax']);
}
}
if ($shipping_products) {
$package = array('contents' => $shipping_products, 'contents_cost' => array_sum(wp_list_pluck($shipping_products, 'line_total')), 'applied_coupons' => array(), 'destination' => array('country' => $parent_order->shipping_country, 'state' => $parent_order->shipping_state, 'postcode' => $parent_order->shipping_postcode, 'city' => $parent_order->shipping_city, 'address' => $parent_order->shipping_address_1, 'address_2' => $parent_order->shipping_address_2));
$wc_shipping = WC_Shipping::instance();
$pack = $wc_shipping->calculate_shipping_for_package($package);
if (array_key_exists($shipping_method['method_id'], $pack['rates'])) {
$method = $pack['rates'][$shipping_method['method_id']];
$cost = wc_format_decimal($method->cost);
$item_id = wc_add_order_item($order_id, array('order_item_name' => $method->label, 'order_item_type' => 'shipping'));
if ($item_id) {
wc_add_order_item_meta($item_id, 'method_id', $method->id);
wc_add_order_item_meta($item_id, 'cost', $cost);
}
return $cost;
}
}
return 0;
}
开发者ID:amirkchetu,项目名称:dokan,代码行数:43,代码来源:wc-functions.php
示例5: add_order_item
/**
* Add an item to the provided order
*
* @since 3.0.0
* @param \WC_Order $order
* @param array $item Parsed item data from CSV
* @param string $type Line item type
* @return int|false ID of the inserted order item, false on failure
*/
private function add_order_item(WC_Order $order, $item, $type)
{
$result = false;
switch ($type) {
case 'line_item':
$product = $this->get_product_for_item($item);
$args = $this->prepare_product_args($item);
$result = $order->add_product($product, $args['qty'], $args);
if (!$result) {
wc_csv_import_suite()->log(sprintf(__('> > Warning: cannot add order item "%s".', 'woocommerce-csv-import-suite'), esc_html($identifier)));
}
break;
case 'shipping':
$args = array('order_item_name' => $item['method_title'], 'order_item_type' => 'shipping');
// we're using wc_add_order_item instead of $order->add_shipping because
// we do not want the order total to be recalculated
$result = wc_add_order_item($order->id, $args);
if (!$result) {
wc_csv_import_suite()->log(sprintf(__('> > Warning: cannot add shipping method "%s".', 'woocommerce-csv-import-suite'), esc_html($item['title'])));
}
break;
case 'tax':
$args = array('order_item_name' => $item['code'], 'order_item_type' => 'tax');
$result = wc_add_order_item($order->id, $args);
if (!$result) {
wc_csv_import_suite()->log(sprintf(__('> > Warning: cannot add tax "%s".', 'woocommerce-csv-import-suite'), esc_html($item['label'])));
}
break;
case 'coupon':
$result = $order->add_coupon($item['code'], $item['amount']);
if (!$result) {
wc_csv_import_suite()->log(sprintf(__('> > Warning: cannot add coupon "%s".', 'woocommerce-csv-import-suite'), esc_html($item['code'])));
}
break;
case 'fee':
$order_fee = new stdClass();
$order_fee->id = sanitize_title($item['title']);
$order_fee->name = $item['title'];
$order_fee->amount = isset($item['total']) ? floatval($item['total']) : 0;
$order_fee->taxable = false;
$order_fee->tax = 0;
$order_fee->tax_data = array();
$order_fee->tax_class = '';
// if taxable, tax class and total are required
if (isset($item['taxable']) && $item['taxable']) {
$order_fee->taxable = true;
$order_fee->tax_class = $item['tax_class'];
if (isset($item['total_tax'])) {
$order_fee->tax = isset($item['total_tax']) ? wc_format_refund_total($item['total_tax']) : 0;
}
if (isset($item['tax_data'])) {
$tax_data = isset($item['tax_data']['total']) ? $item['tax_data']['total'] : $item['tax_data'];
$order_fee->tax = wc_format_refund_total(array_sum($tax_data));
$order_fee->tax_data = array_map('wc_format_refund_total', $tax_data);
}
}
$result = $order->add_fee($order_fee);
if (!$result) {
wc_csv_import_suite()->log(sprintf(__('> > Warning: cannot add fee "%s".', 'woocommerce-csv-import-suite'), esc_html($item['title'])));
}
break;
}
// store original order item ID
if ($result && isset($item['order_item_id']) && $item['order_item_id'] > 0) {
wc_update_order_item_meta($result, '_original_order_item_id', $item['order_item_id']);
}
return $result;
}
开发者ID:arobbins,项目名称:spellestate,代码行数:77,代码来源:class-wc-csv-import-suite-order-import.php
示例6: sync
//.........这里部分代码省略.........
$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];
$item_id = wc_add_order_item($order_id, array('order_item_name' => $productname, 'order_item_type' => 'line_item'));
wc_add_order_item_meta($item_id, '_qty', $qty);
if (!is_null($product_id) && $product_id !== 0) {
wc_add_order_item_meta($item_id, '_product_id', $product_id);
wc_add_order_item_meta($item_id, '_variation_id', $variation_id);
wc_add_order_item_meta($item_id, '_tax_class', '');
} else {
wc_add_order_item_meta($item_id, '_product_id', 0);
wc_add_order_item_meta($item_id, '_variation_id', 0);
wc_add_order_item_meta($item_id, '_tax_class', '');
}
$line_total = wc_format_decimal((double) $orderline->linetotal);
$line_total_tax = wc_format_decimal((double) $orderline->linetotalinctax - (double) $orderline->linetotal);
wc_add_order_item_meta($item_id, '_line_subtotal', $line_total);
wc_add_order_item_meta($item_id, '_line_total', $line_total);
wc_add_order_item_meta($item_id, '_line_subtotal_tax', $line_total_tax);
wc_add_order_item_meta($item_id, '_line_tax', $line_total_tax);
wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(1 => $line_total_tax), 'subtotal' => array(1 => $line_total_tax)));
$tax += $line_total_tax;
} else {
$item_id = wc_add_order_item($order_id, array('order_item_name' => (string) $orderline->productname, 'order_item_type' => 'shipping'));
wc_add_order_item_meta($item_id, 'cost', wc_format_decimal((double) $orderline->linetotal));
$shipping += (double) $orderline->linetotal;
$shipping_tax += (double) $orderline->linetotalinctax - (double) $orderline->linetotal;
}
}
if ($ordercontent->paymentstatus == 'complete') {
$transaction_id = (string) $ordercontent->orderpayments[0]->orderpayment->transactionid;
if ($transaction_id) {
update_post_meta($order_id, '_payment_method', 'paypal');
update_post_meta($order_id, '_payment_method_title', __('PayPal', 'woocommerce'));
update_post_meta($order_id, '_transaction_id', $transaction_id);
} else {
开发者ID:CodistoConnect,项目名称:CodistoConnect-WooCommerce,代码行数:67,代码来源:connect.php
示例7: create_order
/**
* create_order function.
* @access public
* @throws Exception
* @return int
*/
public function create_order()
{
global $wpdb;
// Give plugins the opportunity to create an order themselves
$order_id = apply_filters('woocommerce_create_order', null, $this);
if (is_numeric($order_id)) {
return $order_id;
}
// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected.
$order_data = apply_filters('woocommerce_new_order_data', array('post_type' => 'shop_order', 'post_title' => sprintf(__('Order – %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce'))), 'post_status' => 'publish', 'ping_status' => 'closed', 'post_excerpt' => isset($this->posted['order_comments']) ? $this->posted['order_comments'] : '', 'post_author' => 1, 'post_password' => uniqid('order_')));
// Insert or update the post data
$create_new_order = true;
if (WC()->session->order_awaiting_payment > 0) {
$order_id = absint(WC()->session->order_awaiting_payment);
/* Check order is unpaid by getting its status */
$terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs'));
$order_status = isset($terms[0]) ? $terms[0] : 'pending';
// Resume the unpaid order if its pending
if ($order_status == 'pending' || $order_status == 'failed') {
// Update the existing order as we are resuming it
$create_new_order = false;
$order_data['ID'] = $order_id;
wp_update_post($order_data);
// Clear the old line items - we'll add these again in case they changed
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d )", $order_id));
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d", $order_id));
// Trigger an action for the resumed order
do_action('woocommerce_resume_order', $order_id);
}
}
if ($create_new_order) {
$order_id = wp_insert_post($order_data, true);
if (is_wp_error($order_id)) {
throw new Exception('Error: Unable to create order. Please try again.');
} else {
do_action('woocommerce_new_order', $order_id);
}
}
// Store user data
if ($this->checkout_fields['billing']) {
foreach ($this->checkout_fields['billing'] as $key => $field) {
update_post_meta($order_id, '_' . $key, $this->posted[$key]);
if ($this->customer_id && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) {
update_user_meta($this->customer_id, $key, $this->posted[$key]);
}
}
}
if ($this->checkout_fields['shipping'] && WC()->cart->needs_shipping()) {
foreach ($this->checkout_fields['shipping'] as $key => $field) {
$postvalue = false;
if ($this->posted['ship_to_different_address'] == false) {
if (isset($this->posted[str_replace('shipping_', 'billing_', $key)])) {
$postvalue = $this->posted[str_replace('shipping_', 'billing_', $key)];
update_post_meta($order_id, '_' . $key, $postvalue);
}
} else {
$postvalue = $this->posted[$key];
update_post_meta($order_id, '_' . $key, $postvalue);
}
// User
if ($postvalue && $this->customer_id && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) {
update_user_meta($this->customer_id, $key, $postvalue);
}
}
}
// Save any other user meta
if ($this->customer_id) {
do_action('woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted);
}
// Store the line items to the new/resumed order
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
// Add line item
$item_id = wc_add_order_item($order_id, array('order_item_name' => $_product->get_title(), 'order_item_type' => 'line_item'));
// Add line item meta
if ($item_id) {
wc_add_order_item_meta($item_id, '_qty', apply_filters('woocommerce_stock_amount', $values['quantity']));
wc_add_order_item_meta($item_id, '_tax_class', $_product->get_tax_class());
wc_add_order_item_meta($item_id, '_product_id', $values['product_id']);
wc_add_order_item_meta($item_id, '_variation_id', $values['variation_id']);
wc_add_order_item_meta($item_id, '_line_subtotal', wc_format_decimal($values['line_subtotal']));
wc_add_order_item_meta($item_id, '_line_total', wc_format_decimal($values['line_total']));
wc_add_order_item_meta($item_id, '_line_tax', wc_format_decimal($values['line_tax']));
wc_add_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal($values['line_subtotal_tax']));
// Store variation data in meta so admin can view it
if ($values['variation'] && is_array($values['variation'])) {
foreach ($values['variation'] as $key => $value) {
wc_add_order_item_meta($item_id, esc_attr(str_replace('attribute_', '', $key)), $value);
}
}
// Add line item meta for backorder status
if ($_product->backorders_require_notification() && $_product->is_on_backorder($values['quantity'])) {
wc_add_order_item_meta($item_id, apply_filters('woocommerce_backordered_item_meta_name', __('Backordered', 'woocommerce'), $cart_item_key, $order_id), $values['quantity'] - max(0, $_product->get_total_stock()));
}
//.........这里部分代码省略.........
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:101,代码来源:class-wc-checkout.php
示例8: save
/**
* Save meta box data
*/
public static function save($post_id, $post)
{
global $wpdb;
// Save tax rows
$total_tax = 0;
$total_shipping_tax = 0;
if (isset($_POST['order_taxes_id'])) {
$get_values = array('order_taxes_id', 'order_taxes_rate_id', 'order_taxes_amount', 'order_taxes_shipping_amount');
foreach ($get_values as $value) {
${$value} = isset($_POST[$value]) ? $_POST[$value] : array();
}
foreach ($order_taxes_id as $item_id => $value) {
if ($item_id == 'new') {
foreach ($value as $new_key => $new_value) {
$rate_id = absint($order_taxes_rate_id[$item_id][$new_key]);
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();
}
// 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'));
//.........这里部分代码省略.........
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:101,代码来源:class-wc-meta-box-order-totals.php
示例9: create_renewal_order
//.........这里部分代码省略.........
'_subscriptio_renewal' => 'yes',
);
foreach ($other_meta_fields as $field_key => $field_value) {
update_post_meta($order_id, $field_key, $field_value);
}
// Check if subscription product is variable
$product_id_to_use = !empty($subscription->variation_id) ? $subscription->variation_id : $subscription->product_id;
// Check if product still exists
if (Subscriptio::product_is_active($product_id_to_use)) {
// Load product object
$product = new WC_Product($product_id_to_use);
// Get product name
$product_title = $product->get_title();
// Update product name on subscription if it was changed
if ($product_title != $subscription->product_name) {
$subscription->update_subscription_details(array(
'product_name' => $product_title,
));
}
}
// If not - use saved product "snapshot" from previous order
else {
$product_title = $subscription->product_name;
}
// Add line item (product) to order
$item_id = wc_add_order_item($order_id, array(
'order_item_name' => $product_title,
'order_item_type' => 'line_item',
));
if (!$item_id) {
throw new Exception(__('Unable to add product to renewal order.', 'subscriptio'));
}
// Add line item meta
$item_meta = array(
'_qty' => !empty($subscription->quantity) ? $subscription->quantity : 1,
'_tax_class' => $subscription->renewal_tax_class,
'_product_id' => $subscription->product_id,
'_variation_id' => !empty($subscription->variation_id) ? $subscription->variation_id : '',
'_line_subtotal' => wc_format_decimal($subscription->renewal_line_subtotal),
'_line_subtotal_tax' => wc_format_decimal($subscription->renewal_line_subtotal_tax),
'_line_total' => wc_format_decimal($subscription->renewal_line_total),
'_line_tax' => wc_format_decimal($subscription->renewal_line_tax),
);
foreach ($item_meta as $item_meta_key => $item_meta_value) {
wc_add_order_item_meta($item_id, $item_meta_key, $item_meta_value);
}
// Save shipping info (if any)
if (!empty($subscription->shipping)) {
$shipping_item_id = wc_add_order_item($order_id, array(
'order_item_name' => $subscription->shipping['name'],
'order_item_type' => 'shipping',
));
wc_add_order_item_meta($shipping_item_id, 'method_id', $subscription->shipping['method_id']);
开发者ID:qhuit,项目名称:dcosta,代码行数:67,代码来源:subscriptio-order-handler.class.php
示例10: update_orders
function update_orders()
{
global $wpdb;
// loop through orders
$wpec_order_table = $wpdb->prefix . 'wpsc_purchase_logs';
$wpec_formdata_table = $wpdb->prefix . 'wpsc_submited_form_data';
$order_data = $wpdb->get_results("SELECT * FROM `" . $wpec_order_table . "`", ARRAY_A);
foreach ((array) $order_data as $order) {
$post_title = "WPEC Order - " . $order['id'] . " - " . date('Y-m-d H:i:s', $order['date']);
// check to see if order has already been added
$order_exists = $wpdb->get_var($wpdb->prepare("\n SELECT ID FROM {$wpdb->posts} \n WHERE post_title = %s \n AND post_type = 'shop_order'", $post_title));
if ($order_exists) {
continue;
}
// create a new post with custom post type 'shop_order'
$post = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $this->post_author, 'post_parent' => '0', 'post_status' => 'publish', 'post_title' => $post_title, 'post_type' => 'shop_order');
// insert post
$post_id = wp_insert_post($post, true);
// wpec tables
$wpsc_cart_contents_table = $wpdb->prefix . 'wpsc_cart_contents';
$wpsc_purchase_logs_table = $wpdb->prefix . 'wpsc_purchase_logs';
$wpsc_submited_form_data_table = $wpdb->prefix . 'wpsc_submited_form_data';
$wpsc_checkout_forms_table = $wpdb->prefix . 'wpsc_checkout_forms';
/*
CUSTOMER DATA
*/
$userinfo = $wpdb->get_results("\n SELECT \n `" . $wpsc_submited_form_data_table . "`.`value`,\n `" . $wpsc_checkout_forms_table . "`.`name`,\n `" . $wpsc_checkout_forms_table . "`.`unique_name`\n FROM `" . $wpsc_checkout_forms_table . "`\n LEFT JOIN `" . $wpsc_submited_form_data_table . "`\n ON `" . $wpsc_checkout_forms_table . "`.id = `" . $wpsc_submited_form_data_table . "`.`form_id`\n WHERE `" . $wpsc_submited_form_data_table . "`.`log_id`=" . $order['id'] . "\n ORDER BY `" . $wpsc_checkout_forms_table . "`.`checkout_order`\n ", ARRAY_A);
foreach ($userinfo as $info) {
$userinfo[$info['unique_name']] = $info['value'];
}
// ID
update_post_meta($post_id, '_customer_user', $order['user_ID']);
// billing address
update_post_meta($post_id, '_billing_first_name', $userinfo['billingfirstname']);
update_post_meta($post_id, '_billing_last_name', $userinfo['billinglastname']);
update_post_meta($post_id, '_billing_address_1', $userinfo['billingaddress']);
update_post_meta($post_id, '_billing_address_2', "");
update_post_meta($post_id, '_billing_city', $userinfo['billingcity']);
update_post_meta($post_id, '_billing_postcode', $userinfo['billingpostcode']);
update_post_meta($post_id, '_billing_country', $userinfo['billingcountry']);
update_post_meta($post_id, '_billing_email', $userinfo['billingemail']);
update_post_meta($post_id, '_billing_phone', $userinfo['billingphone']);
// shipping address
update_post_meta($post_id, '_shipping_first_name', $userinfo['shippingfirstname']);
update_post_meta($post_id, '_shipping_last_name', $userinfo['shippinglastname']);
update_post_meta($post_id, '_shipping_company', "");
update_post_meta($post_id, '_shipping_address_1', $userinfo['shippingaddress']);
update_post_meta($post_id, '_shipping_address_2', "");
update_post_meta($post_id, '_shipping_city', $userinfo['shippingcity']);
update_post_meta($post_id, '_shipping_postcode', $userinfo['shippingpostcode']);
update_post_meta($post_id, '_shipping_country', $userinfo['shippingcountry']);
update_post_meta($post_id, '_shipping_state', "");
/*
ORDER ITEMS
*/
$cartcontent = $wpdb->get_results("\n SELECT * \n FROM `" . $wpsc_cart_contents_table . "` \n WHERE `purchaseid`=" . $order['id'] . "\n ");
foreach ($cartcontent as $item) {
$item_id = wc_add_order_item($post_id, array('order_item_name' => $item->name, 'order_item_type' => 'line_item'));
if ($item_id) {
wc_add_order_item_meta($item_id, '_qty', $item->quantity);
wc_add_order_item_meta($item_id, '_product_id', $item->prodid);
wc_add_order_item_meta($item_id, '_variation_id', null);
$subtotal = $item->quantity * $item->price;
wc_add_order_item_meta($item_id, '_line_subtotal', $subtotal);
wc_add_order_item_meta($item_id, '_line_subtotal_tax', $subtotal + $item->tax_charged);
wc_add_order_item_meta($item_id, '_line_total', $subtotal + $item->tax_charged);
wc_add_order_item_meta($item_id, '_line_tax', $item->tax_charged);
}
}
/*
ORDER DATA
*/
$extrainfo = $wpdb->get_results("\n SELECT DISTINCT `" . $wpsc_purchase_logs_table . "` . * \n FROM `" . $wpsc_submited_form_data_table . "`\n LEFT JOIN `" . $wpsc_purchase_logs_table . "`\n ON `" . $wpsc_submited_form_data_table . "`.`log_id` = `" . $wpsc_purchase_logs_table . "`.`id`\n WHERE `" . $wpsc_purchase_logs_table . "`.`id`=" . $order['id'] . "\n ");
$extrainfo = $extrainfo[0];
update_post_meta($post_id, '_payment_method', $extrainfo->gateway);
update_post_meta($post_id, '_order_shipping', $extrainfo->base_shipping);
update_post_meta($post_id, '_order_discount', $extrainfo->base_shipping);
update_post_meta($post_id, '_cart_discount', $extrainfo->base_shipping);
update_post_meta($post_id, '_order_tax', $extrainfo->base_shipping);
update_post_meta($post_id, '_order_shipping_tax', $extrainfo->base_shipping);
update_post_meta($post_id, '_order_total', $extrainfo->totalprice);
update_post_meta($post_id, '_order_key', uniqid('order_'));
update_post_meta($post_id, '_order_currency', "EUR");
update_post_meta($post_id, '_prices_include_tax', "no");
// order date
wp_update_post(array('ID' => $post_id, 'post_date' => date_i18n('Y-m-d H:i:s', $extrainfo->date), 'post_date_gmt' => date_i18n('Y-m-d H:i:s', $extrainfo->date, true)));
// order status
switch ($order['processed']) {
case "1":
$status = 'failed';
break;
case "2":
$status = 'pending';
break;
case "3":
case "4":
$status = 'processing';
break;
case "5":
$status = 'completed';
//.........这里部分代码省略.........
开发者ID:ashishpadhy,项目名称:wp-e-commerce-to-woocommerce-converter,代码行数:101,代码来源:wpec-to-woo.php
示例11: update_cart_by_woocart
public function update_cart_by_woocart($order_id, $data)
{
global $wp;
global $wpdb, $woocommerce, $pwa;
$xml = simplexml_load_string($data);
$order = new WC_Order($order_id);
$billing_address = array('first_name' => (string) $xml->ProcessedOrder->BuyerInfo->BuyerName, 'last_name' => '', 'company' => '', 'email' => (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress, 'phone' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'state' => '', 'postcode' => '', 'country' => '');
$shipping_address = array('first_name' => (string) $xml->ProcessedOrder->ShippingAddress->Name, 'last_name' => '', 'company' => '', 'email' => '', 'phone' => '', 'address_1' => (string) $xml->ProcessedOrder->ShippingAddress->AddressFieldOne, 'address_2' => (string) $xml->ProcessedOrder->ShippingAddress->AddressFieldTwo, 'city' => (string) $xml->ProcessedOrder->ShippingAddress->City, 'state' => (string) $xml->ProcessedOrder->ShippingAddress->State, 'postcode' => (string) $xml->ProcessedOrder->ShippingAddress->PostalCode, 'country' => (string) $xml->ProcessedOrder->ShippingAddress->CountryCode);
$order->set_address($shipping_address, 'shipping');
add_post_meta($order_id, '_payment_method', 'pwa');
add_post_meta($order_id, '_payment_method_title', 'Pay with Amazon');
$total_amount = 0;
$subtotal_amount = 0;
$shipping_amount = 0;
$ClientRequestId = 0;
try {
foreach ($xml->ProcessedOrder->ProcessedOrderItems->ProcessedOrderItem as $item) {
// XML DATA
$ClientRequestId = (int) $item->ClientRequestId;
foreach ($item->ItemCharges->Component as $amount_type) {
$item_charge_type = (string) $amount_type->Type;
if ($item_charge_type == 'Shipping') {
$Shipping = (string) $amount_type->Charge->Amount;
}
}
$shipping_amount = $shipping_amount + $Shipping;
}
} catch (Exception $e) {
$param['message'] = 'IOPN Notifications : Caught exception : ' . $e->getMessage() . '.';
$this->generate_log($param);
}
if ($ClientRequestId == 0) {
$order->set_address($billing_address, 'billing');
}
// CART DATA
$cartdata = '';
$user_id = 0;
$prefix = $wpdb->prefix;
$carts = $wpdb->get_results("SELECT * FROM `" . $prefix . "pwa_before_cart_save` WHERE id = {$ClientRequestId} ");
foreach ($carts as $key => $value) {
$cartdata = maybe_unserialize($value->cart_data);
$user_id = $value->user_id;
}
update_post_meta($order_id, '_customer_user', $user_id);
// ENTRY
try {
foreach ($cartdata->cart_contents as $key => $value) {
$product_id = $value['product_id'];
$cart_product = get_product($product_id);
$product = array();
$product['order_item_name'] = $cart_product->get_title();
$product['order_item_type'] = 'line_item';
$order_item_id = wc_add_order_item($order_id, $product);
wc_add_order_item_meta($order_item_id, '_qty', $value['quantity']);
wc_add_order_item_meta($order_item_id, '_product_id', $product_id);
wc_add_order_item_meta($order_item_id, '_line_total', $value['line_total']);
wc_add_order_item_meta($order_item_id, '_line_subtotal', $value['line_subtotal']);
wc_add_order_item_meta($order_item_id, '_line_tax', $value['line_tax']);
wc_add_order_item_meta($order_item_id, '_line_subtotal_tax', $value['line_subtotal_tax']);
wc_add_order_item_meta($order_item_id, '_line_tax_data', maybe_serialize($value['line_tax_data']));
foreach ($value['line_tax_data']['total'] as $tax_rate_id => $tax_data) {
$tax_class = $wpdb->get_results("SELECT * FROM `" . $prefix . "woocommerce_tax_rates` WHERE tax_rate_id = {$tax_rate_id} ");
wc_add_order_item_meta($order_item_id, '_tax_class', $tax_class[0]->tax_rate_class);
}
if ($value['variation_id'] > 0) {
wc_add_order_item_meta($order_item_id, '_variation_id', $value['variation_id']);
}
foreach ($value['variation'] as $attrib_key => $attrib_value) {
$meta_key = str_replace('attribute_', '', $attrib_key);
wc_add_order_item_meta($order_item_id, $meta_key, $attrib_value);
}
|
请发表评论