A Simple class for managing order item meta so plugins add it in the correct format
Author: WooThemes
function siw_wc_email_show_project_details($order, $application_number)
{
    ?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<?php 
    siw_wc_generate_email_table_header_row('Aanmelding');
    siw_wc_generate_email_table_row('Aanmeldnummer', $application_number);
    foreach ($order->get_items() as $item_id => $item) {
        $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
        $item_meta = new WC_Order_Item_Meta($item, $_product);
        //projectdetails formatteren
        $item_details = apply_filters('woocommerce_order_item_name', $item['name'], $item) . ' (' . get_post_meta($_product->id, 'projectduur', true) . ')';
        if ($item_meta->meta) {
            $item_details .= '<br/><small>' . nl2br($item_meta->display(true, true, '_', "\n")) . '</small>';
        }
        siw_wc_generate_email_table_row('Project', $item_details);
    }
    $discount = $order->get_total_discount();
    $subtotal = $order->get_subtotal();
    $total = $order->get_total();
    //subtotaal alleen tonen als het afwijkt van het totaal
    if ($subtotal != $total) {
        siw_wc_generate_email_table_row('Subtotaal', $order->get_subtotal_to_display());
        siw_wc_generate_email_table_row('Korting', '-' . $order->get_discount_to_display());
    }
    siw_wc_generate_email_table_row('Totaal', $order->get_formatted_order_total());
    siw_wc_generate_email_table_row('Betaalwijze', $order->payment_method_title);
    ?>
	
	</table>
	<?php 
}
Esempio n. 2
0
 /**
  * Sort the data for CSV output first
  *
  * @param int   $product_id
  * @param array $headers
  * @param array $body
  * @param array $items
  */
 public static function output_csv($product_id, $headers, $body, $items)
 {
     $headers['quantity'] = __('Quantity', 'wcvendors');
     $new_body = array();
     foreach ($body as $i => $order) {
         // Remove comments
         unset($body[$i]['comments']);
         // Remove all numeric keys in each order (these are the meta values we are redoing into new lines)
         foreach ($order as $key => $col) {
             if (is_int($key)) {
                 unset($order[$key]);
             }
         }
         // New order row
         $new_row = $body[$i];
         // Remove order to redo
         unset($body[$i]);
         foreach ($items[$i]['items'] as $item) {
             $item_meta = new WC_Order_Item_Meta($item['item_meta']);
             $item_meta_options = $item_meta->get_formatted();
             // $item_meta = $item_meta->display( true, true );
             $new_row_with_meta = $new_row;
             if (sizeof($item_meta_options) > 0) {
                 $new_row_with_meta[] = $item['qty'];
                 foreach ($item_meta_options as $item_meta_option) {
                     if (!array_key_exists($item_meta_option['label'], $headers)) {
                         $headers[$item_meta_option['label']] = $item_meta_option['label'];
                     }
                     $new_row_with_meta[] = $item_meta_option['value'];
                 }
             } else {
                 $new_row_with_meta[] = $item['qty'];
             }
             $new_body[] = $new_row_with_meta;
         }
     }
     $headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
     $body = apply_filters('wcvendors_csv_body', $new_body, $product_id, $items);
     WCV_Export_CSV::download($headers, $body, $product_id);
 }
 /**
  * Add each subscription product's details to an order so that the state of the subscription persists even when a product is changed
  *
  * @since 1.2
  */
 public static function add_order_item_meta($order_item)
 {
     global $woocommerce;
     if (WC_Subscriptions_Product::is_subscription($order_item['id'])) {
         // Make sure existing meta persists
         $item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
         // Add subscription details so order state persists even when a product is changed
         $item_meta->add('_subscription_period', WC_Subscriptions_Product::get_period($order_item['id']));
         $item_meta->add('_subscription_interval', WC_Subscriptions_Product::get_interval($order_item['id']));
         $item_meta->add('_subscription_length', WC_Subscriptions_Product::get_length($order_item['id']));
         $item_meta->add('_subscription_trial_length', WC_Subscriptions_Product::get_trial_length($order_item['id']));
         $item_meta->add('_subscription_trial_period', WC_Subscriptions_Product::get_trial_period($order_item['id']));
         $item_meta->add('_subscription_recurring_amount', $woocommerce->cart->base_recurring_prices[$order_item['id']]);
         // WC_Subscriptions_Product::get_price() would return a price without filters applied
         $item_meta->add('_subscription_sign_up_fee', WC_Subscriptions_Product::get_sign_up_fee($order_item['id']));
         // Calculated recurring amounts for the item
         $item_meta->add('_recurring_line_total', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_total']);
         $item_meta->add('_recurring_line_tax', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_tax']);
         $item_meta->add('_recurring_line_subtotal', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_subtotal']);
         $item_meta->add('_recurring_line_subtotal_tax', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_subtotal_tax']);
         $order_item['item_meta'] = $item_meta->meta;
     }
     return $order_item;
 }
 /**
  * Display meta data belonging to an item
  * @param  array $item
  */
 public function display_item_meta($item)
 {
     $product = $this->get_product_from_item($item);
     $item_meta = new WC_Order_Item_Meta($item, $product);
     $item_meta->display();
 }
        }
        ?>
					<?php 
        $order_item = WC_Subscriptions_Order::get_item_by_product_id($order, $subscription_details['product_id']);
        ?>
					<?php 
        if (WC_Subscriptions::is_woocommerce_pre('2.4')) {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item['item_meta'], $product);
            ?>
					<?php 
        } else {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item, $product);
            ?>
					<?php 
        }
        ?>
					<?php 
        $meta_to_display = $item_meta->display(true, true);
        ?>
					<?php 
        if (!empty($meta_to_display)) {
            ?>
					<p>
					<?php 
            echo $meta_to_display;
            ?>
					</p>
<?php

/**
 * Email Order Items
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates/Emails
 * @version     2.1.2
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
foreach ($items as $item_id => $item) {
    $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
    if (apply_filters('woocommerce_order_item_visible', true, $item)) {
        ?>
		<tr>
			<td style="text-align:left; vertical-align:middle; border: 1px solid #eee; word-wrap:break-word;"><?php 
        // Show title/image etc
        if ($show_image) {
            echo apply_filters('woocommerce_order_item_thumbnail', '<img src="' . ($_product->get_image_id() ? current(wp_get_attachment_image_src($_product->get_image_id(), 'thumbnail')) : wc_placeholder_img_src()) . '" alt="' . __('Product Image', 'woocommerce') . '" height="' . esc_attr($image_size[1]) . '" width="' . esc_attr($image_size[0]) . '" style="vertical-align:middle; margin-right: 10px;" />', $item);
        }
        // Product name
        echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
        // SKU
        if ($show_sku && is_object($_product) && $_product->get_sku()) {
            echo ' (#' . $_product->get_sku() . ')';
        }
        // allow other plugins to add additional product information here
Esempio n. 7
0
                <th class="product-total"><?php 
_e('Total', 'woocommerce');
?>
</th>
            </tr>
        </thead>
       
        <tbody>
            <?php 
if (sizeof($order->get_items()) > 0) {
    foreach ($order->get_items() as $item) {
        $_product = get_product($item['variation_id'] ? $item['variation_id'] : $item['product_id']);
        echo '
					<tr class = "' . esc_attr(apply_filters('woocommerce_order_table_item_class', 'order_table_item', $item, $order)) . '">
						<td class="product-name">' . apply_filters('woocommerce_order_table_product_title', '<a href="' . get_permalink($item['product_id']) . '">' . $item['name'] . '</a>', $item) . ' ' . apply_filters('woocommerce_order_table_item_quantity', '<strong class="product-quantity">&times; ' . $item['qty'] . '</strong>', $item);
        $item_meta = new WC_Order_Item_Meta($item['item_meta']);
        $item_meta->display();
        if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
            $download_file_urls = $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item);
            $i = 0;
            $links = array();
            foreach ($download_file_urls as $file_url => $download_file_url) {
                $filename = woocommerce_get_filename_from_url($file_url);
                $links[] = '<small><a href="' . $download_file_url . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_file_urls) > 1 ? ' ' . ($i + 1) . ': ' : ': ') . $filename . '</a></small>';
                $i++;
            }
            echo implode('<br/>', $links);
        }
        echo '</td><td class="product-total">' . $order->get_formatted_line_subtotal($item) . '</td></tr>';
        // Show any purchase notes
        if ($order->status == 'completed' || $order->status == 'processing') {
 /**
  * Get the invoice line items for a given order. This includes:
  *
  * + Products, mapped as FreshBooks items when the admin has linked them
  * + Fees, mapped as a `Fee` item
  * + Shipping, mapped as a `Shipping` item
  * + Taxes, mapped using the tax code as the item
  *
  * Note that taxes cannot be added per-product as WooCommerce doesn't provide
  * any way to get individual tax information per product and FreshBooks requires
  * a tax name/percentage to be set on a per-product basis. Further, FreshBooks
  * only allows 2 taxes per product where realistically most stores will have
  * more
  *
  * @param \WC_FreshBooks_Order $order order instance
  * @return array line items
  * @since 3.0
  */
 private function get_invoice_lines(WC_FreshBooks_Order $order)
 {
     $line_items = array();
     // add products
     foreach ($order->get_items() as $item_key => $item) {
         $product = $order->get_product_from_item($item);
         // must be a valid product
         if (is_object($product)) {
             $product_id = $product->is_type('variation') ? $product->variation_id : $product->id;
             $item_name = metadata_exists('post', $product_id, '_wc_freshbooks_item_name') ? get_post_meta($product_id, '_wc_freshbooks_item_name', true) : $product->get_sku();
             $item_meta = new WC_Order_Item_Meta(SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta']);
             // variation data, item meta, etc
             $meta = $item_meta->display(true, true);
             // grouped products include a &arr; in the name which must be converted back to an arrow
             $item_description = html_entity_decode($product->get_title(), ENT_QUOTES, 'UTF-8') . ($meta ? sprintf(' (%s)', $meta) : '');
         } else {
             $item_name = __('Product', WC_FreshBooks::TEXT_DOMAIN);
             $item_description = $item['name'];
         }
         $line_items[] = array('name' => $item_name, 'description' => apply_filters('wc_freshbooks_line_item_description', $item_description, $item, $order, $item_key), 'unit_cost' => $order->get_item_subtotal($item), 'quantity' => $item['qty']);
     }
     $coupons = $order->get_items('coupon');
     // add coupons
     foreach ($coupons as $coupon_item) {
         $coupon = new WC_Coupon($coupon_item['name']);
         $coupon_post = get_post($coupon->id);
         $coupon_type = false !== strpos($coupon->type, '_cart') ? __('Cart Discount', WC_FreshBooks::TEXT_DOMAIN) : __('Product Discount', WC_FreshBooks::TEXT_DOMAIN);
         $line_items[] = array('name' => $coupon_item['name'], 'description' => is_object($coupon_post) && $coupon_post->post_excerpt ? sprintf(__('%s - %s', WC_FreshBooks::TEXT_DOMAIN), $coupon_type, $coupon_post->post_excerpt) : $coupon_type, 'unit_cost' => wc_format_decimal($coupon_item['discount_amount'] * -1, 2), 'quantity' => 1);
     }
     // manually created orders can't have coupon items, but may have an order discount set
     // which must be added as a line item
     if (0 == count($coupons) && $order->get_total_discount() > 0) {
         $line_items[] = array('name' => __('Order Discount', WC_FreshBooks::TEXT_DOMAIN), 'description' => __('Order Discount', WC_FreshBooks::TEXT_DOMAIN), 'unit_cost' => wc_format_decimal($order->get_total_discount() * -1, 2), 'quantity' => 1);
     }
     // add fees
     foreach ($order->get_fees() as $fee_key => $fee) {
         $line_items[] = array('name' => __('Fee', WC_FreshBooks::TEXT_DOMAIN), 'description' => $fee['name'], 'unit_cost' => $order->get_line_total($fee), 'quantity' => 1);
     }
     // add shipping
     foreach ($order->get_shipping_methods() as $shipping_method_key => $shipping_method) {
         $line_items[] = array('name' => __('Shipping', WC_FreshBooks::TEXT_DOMAIN), 'description' => ucwords(str_replace('_', ' ', $shipping_method['method_id'])), 'unit_cost' => $shipping_method['cost'], 'quantity' => 1);
     }
     // add taxes
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $line_items[] = array('name' => $tax_code, 'description' => $tax->label, 'unit_cost' => number_Format($tax->amount, 2, '.', ''), 'quantity' => 1);
     }
     return $line_items;
 }
 /**
  * Get order item names as a string
  * @param  WC_Order $order
  * @param  array $item
  * @return string
  */
 protected function get_order_item_name($order, $item)
 {
     $item_name = $item['name'];
     $item_meta = new WC_Order_Item_Meta($item);
     if ($meta = $item_meta->display(true, true)) {
         $item_name .= ' ( ' . $meta . ' )';
     }
     return $item_name;
 }
Esempio n. 10
0
 /**
  * Get an order refund for the given order ID and ID
  *
  * @since 2.2
  * @param string $order_id order ID
  * @param string|null $fields fields to limit response to
  * @return array
  */
 public function get_order_refund($order_id, $id, $fields = null)
 {
     try {
         // Validate order ID
         $order_id = $this->validate_request($order_id, $this->post_type, 'read');
         if (is_wp_error($order_id)) {
             return $order_id;
         }
         $id = absint($id);
         if (empty($id)) {
             throw new WC_API_Exception('woocommerce_api_invalid_order_refund_id', __('Invalid order refund ID', 'woocommerce'), 400);
         }
         $order = wc_get_order($id);
         $refund = wc_get_order($id);
         if (!$refund) {
             throw new WC_API_Exception('woocommerce_api_invalid_order_refund_id', __('An order refund with the provided ID could not be found', 'woocommerce'), 404);
         }
         $line_items = array();
         // Add line items
         foreach ($refund->get_items('line_item') as $item_id => $item) {
             $product = $order->get_product_from_item($item);
             $meta = new WC_Order_Item_Meta($item, $product);
             $item_meta = array();
             foreach ($meta->get_formatted() as $meta_key => $formatted_meta) {
                 $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
             }
             $line_items[] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item), 2), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], 2), 'total' => wc_format_decimal($order->get_line_total($item), 2), 'total_tax' => wc_format_decimal($order->get_line_tax($item), 2), 'price' => wc_format_decimal($order->get_item_total($item), 2), 'quantity' => (int) $item['qty'], 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => isset($product->variation_id) ? $product->variation_id : $product->id, 'sku' => is_object($product) ? $product->get_sku() : null, 'meta' => $item_meta, 'refunded_item_id' => (int) $item['refunded_item_id']);
         }
         $order_refund = array('id' => $refund->id, 'created_at' => $this->server->format_datetime($refund->date), 'amount' => wc_format_decimal($refund->get_refund_amount(), 2), 'reason' => $refund->get_refund_reason(), 'line_items' => $line_items);
         return array('order_refund' => apply_filters('woocommerce_api_order_refund_response', $order_refund, $id, $fields, $refund, $order_id, $this));
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
 /**
  * Get the current order items
  */
 public function get_order_items()
 {
     global $woocommerce;
     global $_product;
     $items = $this->order->get_items();
     $data_list = array();
     if (sizeof($items) > 0) {
         foreach ($items as $item_id => $item) {
             // Array with data for the pdf template
             $data = array();
             // Set the item_id
             $data['item_id'] = $item_id;
             // Set the id
             $data['product_id'] = $item['product_id'];
             $data['variation_id'] = $item['variation_id'];
             // Set item name
             $data['name'] = $item['name'];
             // Set item quantity
             $data['quantity'] = $item['qty'];
             // Set the line total (=after discount)
             $data['line_total'] = $this->wc_price($item['line_total']);
             $data['single_line_total'] = $this->wc_price($item['line_total'] / max(1, $item['qty']));
             $data['line_tax'] = $this->wc_price($item['line_tax']);
             $data['single_line_tax'] = $this->wc_price($item['line_tax'] / max(1, $item['qty']));
             $line_tax_data = maybe_unserialize(isset($item['line_tax_data']) ? $item['line_tax_data'] : '');
             $data['tax_rates'] = $this->get_tax_rate($item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data);
             // Set the line subtotal (=before discount)
             $data['line_subtotal'] = $this->wc_price($item['line_subtotal']);
             $data['line_subtotal_tax'] = $this->wc_price($item['line_subtotal_tax']);
             $data['ex_price'] = $this->get_formatted_item_price($item, 'total', 'excl');
             $data['price'] = $this->get_formatted_item_price($item, 'total');
             $data['order_price'] = $this->order->get_formatted_line_subtotal($item);
             // formatted according to WC settings
             // Calculate the single price with the same rules as the formatted line subtotal (!)
             // = before discount
             $data['ex_single_price'] = $this->get_formatted_item_price($item, 'single', 'excl');
             $data['single_price'] = $this->get_formatted_item_price($item, 'single');
             // Pass complete item array
             $data['item'] = $item;
             // Create the product to display more info
             $data['product'] = null;
             $product = $this->order->get_product_from_item($item);
             // Checking fo existance, thanks to MDesigner0
             if (!empty($product)) {
                 // Set the thumbnail id DEPRICATED (does not support thumbnail sizes), use thumbnail_path or thumbnail instead
                 $data['thumbnail_id'] = $this->get_thumbnail_id($product);
                 // Thumbnail (full img tag)
                 $data['thumbnail'] = $this->get_thumbnail($product);
                 // Set the single price (turned off to use more consistent calculated price)
                 // $data['single_price'] = woocommerce_price ( $product->get_price() );
                 // Set item SKU
                 $data['sku'] = $product->get_sku();
                 // Set item weight
                 $data['weight'] = $product->get_weight();
                 // Set item dimensions
                 $data['dimensions'] = $product->get_dimensions();
                 // Pass complete product object
                 $data['product'] = $product;
             }
             // Set item meta
             if (version_compare(WOOCOMMERCE_VERSION, '2.4', '<')) {
                 $meta = new WC_Order_Item_Meta($item['item_meta'], $product);
             } else {
                 // pass complete item for WC2.4+
                 $meta = new WC_Order_Item_Meta($item, $product);
             }
             $data['meta'] = $meta->display(false, true);
             $data_list[$item_id] = apply_filters('wpo_wcpdf_order_item_data', $data, $this->order);
         }
     }
     return apply_filters('wpo_wcpdf_order_items_data', $data_list, $this->order);
 }
                <th><?php 
    _e('Quantity', 'wc_shipping_multiple_address');
    ?>
</th>
            </tr>
            </thead>
            <tbody>
            <?php 
    foreach ($shipment->get_items() as $item) {
        // get the product; if this variation or product has been deleted, this will return null...
        $_product = $shipment->get_product_from_item($item);
        $sku = $variation = '';
        if ($_product) {
            $sku = $_product->get_sku();
        }
        $item_meta = new WC_Order_Item_Meta($item['item_meta']);
        // first, is there order item meta avaialble to display?
        $variation = $item_meta->display(true, true);
        if (!$variation && $_product && isset($_product->variation_data)) {
            // otherwise (for an order added through the admin) lets display the formatted variation data so we have something to fall back to
            $variation = wc_get_formatted_variation($_product->variation_data, true);
        }
        if ($variation) {
            $variation = '<br/><small>' . $variation . '</small>';
        }
        ?>
                <tr>
                    <td><?php 
        echo apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $variation;
        ?>
</td>
 /**
  * Get the order data format for a single column for all line items, compatible with the legacy (pre 3.0) CSV Export format
  *
  * Note this code was adapted from the old code to maintain compatibility as close as possible, so it should
  * not be modified unless absolutely necessary
  *
  * @since 3.0
  * @param array $order_data an array of order data for the given order
  * @param WC_Order $order the WC_Order object
  * @return array modified order data
  */
 private function get_legacy_single_column_line_item($order_data, WC_Order $order)
 {
     $line_items = array();
     foreach ($order->get_items() as $_ => $item) {
         $product = $order->get_product_from_item($item);
         if (!is_object($product)) {
             $product = new WC_Product(0);
         }
         $line_item = $item['name'];
         if ($product->get_sku()) {
             $line_item .= ' (' . $product->get_sku() . ')';
         }
         $line_item .= ' x' . $item['qty'];
         $item_meta = new WC_Order_Item_Meta($item);
         $variation = $item_meta->display(true, true);
         if ($variation) {
             $line_item .= ' - ' . str_replace(array("\r", "\r\n", "\n"), '', $variation);
         }
         $line_items[] = str_replace(array('&#8220;', '&#8221;'), '', $line_item);
     }
     $order_data['order_items'] = implode('; ', $line_items);
     // convert country codes to full name
     if (isset(WC()->countries->countries[$order->billing_country])) {
         $order_data['billing_country'] = WC()->countries->countries[$order->billing_country];
     }
     if (isset(WC()->countries->countries[$order->shipping_country])) {
         $order_data['shipping_country'] = WC()->countries->countries[$order->shipping_country];
     }
     // set order ID to order number
     $order_data['order_id'] = ltrim($order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-customer-order-csv-export'));
     return $order_data;
 }
 public static function calculate($order, $send_items = false)
 {
     $PaymentOrderItems = array();
     $ctr = $giftwrapamount = $total_items = $total_discount = $total_tax = $shipping = 0;
     $ITEMAMT = 0;
     if ($order) {
         $order_total = $order->get_total();
         $items = $order->get_items();
         /*
          * Set shipping and tax values.
          */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = $order->get_total_shipping() + $order->get_shipping_tax();
             $tax = 0;
         } else {
             $shipping = $order->get_total_shipping();
             $tax = $order->get_total_tax();
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             $tax = $order->get_total_tax();
         }
     } else {
         //if empty order we get data from cart
         $order_total = WC()->cart->total;
         $items = WC()->cart->get_cart();
         /**
          * Get shipping and tax.
          */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = WC()->cart->shipping_total + WC()->cart->shipping_tax_total;
             $tax = 0;
         } else {
             $shipping = WC()->cart->shipping_total;
             $tax = WC()->cart->get_taxes_total();
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             $tax = WC()->cart->get_taxes_total();
         }
     }
     if ($send_items) {
         foreach ($items as $item) {
             /*
              * Get product data from WooCommerce
              */
             if ($order) {
                 $_product = $order->get_product_from_item($item);
                 $qty = absint($item['qty']);
                 $item_meta = new WC_Order_Item_Meta($item, $_product);
                 $meta = $item_meta->display(true, true);
             } else {
                 $_product = $item['data'];
                 $qty = absint($item['quantity']);
                 $meta = WC()->cart->get_item_data($item, true);
             }
             $sku = $_product->get_sku();
             $item['name'] = html_entity_decode($_product->get_title(), ENT_NOQUOTES, 'UTF-8');
             if ($_product->product_type == 'variation') {
                 if (empty($sku)) {
                     $sku = $_product->parent->get_sku();
                 }
                 if (!empty($meta)) {
                     $item['name'] .= " - " . str_replace(", \n", " - ", $meta);
                 }
             }
             $Item = array('name' => $item['name'], 'desc' => '', 'amt' => self::round($item['line_subtotal'] / $qty), 'number' => $sku, 'qty' => $qty);
             array_push($PaymentOrderItems, $Item);
             $ITEMAMT += self::round($item['line_subtotal'] / $qty) * $qty;
         }
         /**
          * Add custom Woo cart fees as line items
          */
         foreach (WC()->cart->get_fees() as $fee) {
             $Item = array('name' => $fee->name, 'desc' => '', 'amt' => self::number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1);
             /**
              * The gift wrap amount actually has its own parameter in
              * DECP, so we don't want to include it as one of the line
              * items.
              */
             if ($Item['number'] != 'gift-wrap') {
                 array_push($PaymentOrderItems, $Item);
                 $ITEMAMT += self::round($fee->amount);
             } else {
                 $giftwrapamount = self::round($fee->amount);
             }
             $ctr++;
         }
         //caculate discount
         if ($order) {
             if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) {
                 if ($order->get_cart_discount() > 0) {
                     foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                         $Item = array('name' => 'Cart Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                     }
                     $total_discount -= $order->get_cart_discount();
                 }
                 if ($order->get_order_discount() > 0) {
                     foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                         $Item = array('name' => 'Order Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                     }
                     $total_discount -= $order->get_order_discount();
                 }
             } else {
                 if ($order->get_total_discount() > 0) {
                     $Item = array('name' => 'Total Discount', 'qty' => 1, 'amt' => -self::number_format($order->get_total_discount()), 'number' => implode(", ", $order->get_used_coupons()));
                     array_push($PaymentOrderItems, $Item);
                     $total_discount -= $order->get_total_discount();
                 }
             }
         } else {
             if (WC()->cart->get_cart_discount_total() > 0) {
                 foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                     $Item = array('name' => 'Cart Discount', 'qty' => '1', 'number' => $code, 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                     array_push($PaymentOrderItems, $Item);
                     $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]);
                 }
             }
             if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) {
                 if (WC()->cart->get_order_discount_total() > 0) {
                     foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                         $Item = array('name' => 'Order Discount', 'qty' => '1', 'number' => $code, 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                         $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]);
                     }
                 }
             }
         }
     }
     if ($tax > 0) {
         $tax = self::number_format($tax);
     }
     if ($shipping > 0) {
         $shipping = self::number_format($shipping);
     }
     if ($total_discount) {
         $total_discount = self::round($total_discount);
     }
     if (empty($ITEMAMT)) {
         $cart_fees = WC()->cart->get_fees();
         if (isset($cart_fees[0]->id) && $cart_fees[0]->id == 'gift-wrap') {
             $giftwrapamount = isset($cart_fees[0]->amount) ? $cart_fees[0]->amount : 0;
         } else {
             $giftwrapamount = 0;
         }
         $Payment['itemamt'] = $order_total - $tax - $shipping - $giftwrapamount;
     } else {
         $Payment['itemamt'] = self::number_format($ITEMAMT + $total_discount);
     }
     /*
      * Set tax
      */
     if ($tax > 0) {
         $Payment['taxamt'] = self::number_format($tax);
         // Required if you specify itemized L_TAXAMT fields.  Sum of all tax items in this order.
     } else {
         $Payment['taxamt'] = 0;
     }
     /*
      * Set shipping
      */
     if ($shipping > 0) {
         $Payment['shippingamt'] = self::number_format($shipping);
         // Total shipping costs for this order.  If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
     } else {
         $Payment['shippingamt'] = 0;
     }
     $Payment['order_items'] = $PaymentOrderItems;
     // Rounding amendment
     if (trim(self::number_format($order_total)) !== trim(self::number_format($Payment['itemamt'] + $giftwrapamount + $tax + $shipping))) {
         $diffrence_amount = AngellEYE_Gateway_Paypal::get_diffrent($order_total, $Payment['itemamt'] + $tax + $shipping);
         if ($shipping > 0) {
             $Payment['shippingamt'] = self::number_format($shipping + $diffrence_amount);
         } elseif ($tax > 0) {
             $Payment['taxamt'] = self::number_format($tax + $diffrence_amount);
         } else {
             //make change to itemamt
             $Payment['itemamt'] = self::number_format($Payment['itemamt'] + $diffrence_amount);
             //also make change to the first item
             if ($send_items) {
                 $Payment['order_items'][0]['amt'] = self::number_format($Payment['order_items'][0]['amt'] + $diffrence_amount / $Payment['order_items'][0]['qty']);
             }
         }
     }
     return $Payment;
 }
 /**
  * ConfirmPayment
  *
  * Finalizes the checkout with PayPal's DoExpressCheckoutPayment API
  *
  * @FinalPaymentAmt (double) Final payment amount for the order.
  */
 function ConfirmPayment($FinalPaymentAmt)
 {
     /*
      * Display message to user if session has expired.
      */
     if (sizeof(WC()->cart->get_cart()) == 0) {
         $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage &rarr;</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"');
         $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms);
         wc_add_notice($ec_confirm_message, "error");
     }
     /*
      * Check if the PayPal class has already been established.
      */
     if (!class_exists('Angelleye_PayPal')) {
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php';
     }
     /*
      * Create PayPal object.
      */
     $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature);
     $PayPal = new Angelleye_PayPal($PayPalConfig);
     /*
      * Get data from WooCommerce object
      */
     if (!empty($this->confirm_order_id)) {
         $order = new WC_Order($this->confirm_order_id);
         $invoice_number = preg_replace("/[^0-9]/", "", $order->get_order_number());
         if ($order->customer_note) {
             $customer_notes = wptexturize($order->customer_note);
         }
         $shipping_first_name = $order->shipping_first_name;
         $shipping_last_name = $order->shipping_last_name;
         $shipping_address_1 = $order->shipping_address_1;
         $shipping_address_2 = $order->shipping_address_2;
         $shipping_city = $order->shipping_city;
         $shipping_state = $order->shipping_state;
         $shipping_postcode = $order->shipping_postcode;
         $shipping_country = $order->shipping_country;
     }
     // Prepare request arrays
     $DECPFields = array('token' => urlencode($this->get_session('TOKEN')), 'payerid' => urlencode($this->get_session('payer_id')), 'returnfmfdetails' => '', 'giftmessage' => $this->get_session('giftmessage'), 'giftreceiptenable' => $this->get_session('giftreceiptenable'), 'giftwrapname' => $this->get_session('giftwrapname'), 'giftwrapamount' => $this->get_session('giftwrapamount'), 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => '');
     $Payments = array();
     $order_items_own = array();
     $final_order_total = $order->get_order_item_totals();
     $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency());
     $final_order_total_amt_strip_ec = strip_tags($final_order_total['order_total']['value']);
     $final_order_total_amt_strip = str_replace(',', '', $final_order_total_amt_strip_ec);
     $final_order_total_amt = str_replace($current_currency, '', $final_order_total_amt_strip);
     $Payment = array('amt' => number_format($final_order_total_amt, 2, '.', ''), 'currencycode' => get_woocommerce_currency(), 'shippingdiscamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'desc' => '', 'custom' => '', 'invnum' => preg_replace("/[^0-9]/", "", $this->confirm_order_id), 'notifyurl' => '', 'shiptoname' => $shipping_first_name . ' ' . $shipping_last_name, 'shiptostreet' => $shipping_address_1, 'shiptostreet2' => $shipping_address_2, 'shiptocity' => $shipping_city, 'shiptostate' => $shipping_state, 'shiptozip' => $shipping_postcode, 'shiptocountrycode' => $shipping_country, 'shiptophonenum' => '', 'notetext' => $this->get_session('customer_notes'), 'allowedpaymentmethod' => '', 'paymentaction' => $this->payment_action == 'Authorization' ? 'Authorization' : 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '', 'sellerid' => '', 'sellerusername' => '', 'sellerregistrationdate' => '', 'softdescriptor' => '');
     $PaymentOrderItems = array();
     $ctr = $total_items = $total_discount = $total_tax = $shipping = 0;
     $ITEMAMT = 0;
     $counter = 1;
     if (sizeof($order->get_items()) > 0) {
         //   if ($this->send_items) {
         foreach ($order->get_items() as $values) {
             $_product = $order->get_product_from_item($values);
             $qty = absint($values['qty']);
             $sku = $_product->get_sku();
             $values['name'] = html_entity_decode($values['name'], ENT_NOQUOTES, 'UTF-8');
             if ($_product->product_type == 'variation') {
                 if (empty($sku)) {
                     $sku = $_product->parent->get_sku();
                 }
                 //$item_meta = new WC_Order_Item_Meta($values['item_meta']);
                 $item_meta = new WC_Order_Item_Meta($values, $_product);
                 $meta = $item_meta->display(true, true);
                 if (!empty($meta)) {
                     $values['name'] .= " - " . str_replace(", \n", " - ", $meta);
                 }
             }
             //////////////////////////////////////////***************************////////////////////////////////////
             $lineitems_prepare = $this->prepare_line_items($order);
             $lineitems = $_SESSION['line_item'];
             if (in_array($values['product_id'], $lineitems)) {
                 $arraykey = array_search($values['product_id'], $lineitems);
                 $item_position = str_replace('product_number_', '', $arraykey);
                 $get_amountkey = 'amount_' . $counter;
                 $get_qtykey = 'quantity_' . $counter;
                 $switcher_amt = $lineitems[$get_amountkey];
                 $switcher_qty = $lineitems[$get_qtykey];
                 $counter = $counter + 1;
             }
             //////////////////////////////////////////***************************////////////////////////////////////
             $Item = array('name' => $values['name'], 'desc' => '', 'amt' => round($switcher_amt, 2), 'number' => $sku, 'qty' => $qty, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
             array_push($PaymentOrderItems, $Item);
             $ITEMAMT += round($switcher_amt, 2) * $switcher_qty;
             $order_items_own[] = round($switcher_amt, 2) * $switcher_qty;
         }
         /**
          * Add custom Woo cart fees as line items
          */
         foreach (WC()->cart->get_fees() as $fee) {
             $Item = array('name' => $fee->name, 'desc' => '', 'amt' => number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
             /**
              * The gift wrap amount actually has its own parameter in
              * DECP, so we don't want to include it as one of the line
              * items.
              */
             if ($Item['number'] != 'gift-wrap') {
                 array_push($PaymentOrderItems, $Item);
                 $ITEMAMT += $fee->amount * $Item['qty'];
                 $order_items_own[] = $fee->amount * $Item['qty'];
             }
             $ctr++;
         }
         if (!$this->is_wc_version_greater_2_3()) {
             /*
              * Get discounts
              */
             if ($order->get_order_discount() > 0) {
                 // foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                 $Item = array('name' => 'Cart Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format(WC()->cart->coupon_discount_amounts[$code], 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 //}
                 $total_discount -= $order->get_cart_discount();
                 $order_items_own[] = $fee->amount * $Item['qty'];
             }
             if ($order->get_order_discount() > 0) {
                 //  foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                 $Item = array('name' => 'Order Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format($order->get_order_discount(), 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 //  }
                 $total_discount -= $order->get_order_discount();
                 $order_items_own[] = round($total_discount, 2);
             }
         } else {
             if ($order->get_total_discount() > 0) {
                 $Item = array('name' => 'Total Discount', 'qty' => 1, 'amt' => -number_format($order->get_total_discount(), 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 $total_discount -= $order->get_total_discount();
                 $order_items_own[] = round($total_discount, 2);
             }
         }
         //   } if(this->senditem)1876
         /*
          * Set shipping and tax values.
          */
         /*             * *****************************MD******************************** */
         foreach ($order->get_tax_totals() as $code => $tax) {
             $tax_string_array[] = $tax->formatted_amount;
         }
         $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency());
         if (isset($tax_string_array) && !empty($tax_string_array)) {
             $striped_amt = strip_tags($tax_string_array[0]);
             if (isset($striped_amt) && !empty($striped_amt)) {
                 $tot_tax = str_replace($current_currency, '', $striped_amt);
             }
         }
         /*             * ****************************MD******************************** */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = $order->get_total_shipping();
             //+ $order->get_shipping_tax();
             $tax = 0;
         } else {
             $shipping = $order->get_total_shipping();
             if (isset($tot_tax) && !empty($tot_tax)) {
                 $tax = $tot_tax;
             } else {
                 $tax = 0;
             }
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             if (isset($tot_tax) && !empty($tot_tax)) {
                 $tax = $tot_tax;
             } else {
                 $tax = 0;
             }
         }
         if ($tax > 0) {
             $tax = number_format($tot_tax, 2, '.', '');
         }
         if ($shipping > 0) {
             $shipping = number_format($shipping, 2, '.', '');
         }
         if ($total_discount) {
             $total_discount = round($total_discount, 2);
         }
         if ($this->send_items) {
             /*
              * Now that we have all items and subtotals
              * we can fill in necessary values.
              */
             $Payment['itemamt'] = number_format($ITEMAMT + $total_discount, 2, '.', '');
         } else {
             $PaymentOrderItems = array();
             $Payment['itemamt'] = number_format($ITEMAMT + $total_discount, 2, '.', '');
         }
         /*
          * Set tax
          */
         if ($tax > 0) {
             $Payment['taxamt'] = number_format($tot_tax, 2, '.', '');
             // Required if you specify itemized L_TAXAMT fields.  Sum of all tax items in this order.
         }
         /*
          * Set shipping
          */
         if ($shipping > 0) {
             $Payment['shippingamt'] = number_format($shipping, 2, '.', '');
             // Total shipping costs for this order.  If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
         }
     }
     $Payment['order_items'] = $PaymentOrderItems;
     array_push($Payments, $Payment);
     $UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
     $PayPalRequestData = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
     // Rounding amendment
     if (isset($tax) && !empty($tax)) {
         $tax = $tax;
     } else {
         $tax = '0.00';
     }
     if (isset($shipping) && !empty($shipping)) {
         $shipping = $shipping;
     } else {
         $shipping = '0.00';
     }
     if (trim(number_format($final_order_total_amt, 2, '.', '')) !== trim(number_format($Payment['itemamt'] + number_format($tax, 2, '.', '') + number_format($shipping, 2, '.', ''), 2, '.', ''))) {
         $diffrence_amount = $this->get_diffrent($final_order_total_amt, $Payment['itemamt'] + $tax + number_format($shipping, 2, '.', ''));
         if ($shipping > 0) {
             $PayPalRequestData['Payments'][0]['shippingamt'] = round($shipping + $diffrence_amount, 2);
         } elseif ($tax > 0) {
             $PayPalRequestData['Payments'][0]['taxamt'] = round($tax + $diffrence_amount, 2);
         } else {
             $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] + $diffrence_amount, 2);
         }
     }
     /* rounding amount */
     $order_item_total = 0;
     foreach ($order_items_own as $keypayment => $valuepayment) {
         $order_item_total = $order_item_total + $valuepayment;
     }
     if ($shipping <= 0 && $tax <= 0) {
         $diffrence_amount_rounded = $this->get_diffrent($final_order_total_amt, $order_item_total);
         $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] - $diffrence_amount_rounded, 2);
         $PayPalRequestData['Payments'][0]['amt'] = round($PayPalRequestData['Payments'][0]['amt'] - $diffrence_amount_rounded, 2);
     }
     // Pass data into class for processing with PayPal and load the response array into $PayPalResult
     $PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData);
     /*
      * Log API result
      */
     $this->add_log('Test Mode: ' . $this->testmode);
     $this->add_log('Endpoint: ' . $this->API_Endpoint);
     $PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : '';
     $PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : '';
     $this->add_log('Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true));
     $this->add_log('Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true));
     /*
      * Error handling
      */
     if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
         $this->remove_session('TOKEN');
         if (isset($_SESSION['line_item'])) {
             unset($_SESSION['line_item']);
         }
     }
     /*
      * Return the class library result array.
      */
     return $PayPalResult;
 }
 /**
  * plain_vendor_order_item_table function to get the plain html of item table of a vendor.
  * @access public
  * @param order id , vendor term id 
  */
 public function plain_vendor_order_item_table($order, $vendor_id, $is_ship = false)
 {
     global $WCMp;
     require_once 'class-wcmp-calculate-commission.php';
     $commission_obj = new WCMp_Calculate_Commission();
     $vendor_items = $this->get_vendor_items_from_order($order->id, $vendor_id);
     foreach ($vendor_items as $item_id => $item) {
         $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
         $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
         // Title
         echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
         // Variation
         echo $item_meta->meta ? "\n" . $item_meta->display(true, true) : '';
         // Quantity
         echo "\n" . sprintf(__('Quantity: %s', $WCMp->text_domain), $item['qty']);
         if (isset($item['variation_id']) && !empty($item['variation_id'])) {
             $variation_id = $item['variation_id'];
         }
         $product_id = $item['product_id'];
         if ($is_ship) {
             echo "\n" . sprintf(__('Total: %s', $WCMp->text_domain), $order->get_formatted_line_subtotal($item));
         } else {
             echo "\n" . sprintf(__('Commission: %s', $WCMp->text_domain), $commission_obj->get_item_commission($product_id, $variation_id, $item, $order->id, $item_id));
         }
         echo "\n\n";
     }
 }
 $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
 $order->set_total(WC()->cart->total);
 // Cart Contents
 if (sizeof($order->get_items()) > 0) {
     foreach ($order->get_items() as $item) {
         if ($item['qty']) {
             $_product = $order->get_product_from_item($item);
             // We manually calculate the tax percentage here
             if ($_product->is_taxable() && $order->get_line_tax($item) > 0) {
                 // Calculate tax percentage
                 $item_tax_percentage = round($order->get_item_tax($item, false) / $order->get_item_total($item, false, false), 2) * 100;
             } else {
                 $item_tax_percentage = 00;
             }
             $item_name = $item['name'];
             $item_meta = new WC_Order_Item_Meta($item);
             if ($meta = $item_meta->display(true, true)) {
                 $item_name .= ' ( ' . $meta . ' )';
             }
             // apply_filters to item price so we can filter this if needed
             $hygglig_item_price_including_tax = $order->get_item_total($item, true);
             $item_price = apply_filters('hygglig_item_price_including_tax', $hygglig_item_price_including_tax);
             // Get SKU or product id [TEMP ONLY USE ID]
             $reference = $_product->id;
             //If variation of product - add ID
             if ($item['variation_id']) {
                 $reference .= $item['variation_id'];
             }
             //Get product description
             $product_description = trim(get_post($item['product_id'])->post_content);
             //Fix desc
Esempio n. 18
0
function access_woocommerce_view_order($order_id)
{
    global $woocommerce;
    $order = new WC_Order($order_id);
    ?>
    <div class="avada-order-details woocommerce-content-box full-width">
        <h2><?php 
    _e('Order Details', 'woocommerce');
    ?>
</h2>
        <table class="shop_table order_details">
            <thead>
            <tr>
                <th class="product-name"><?php 
    _e('Product', 'woocommerce');
    ?>
</th>
                <th class="product-quantity"><?php 
    _e('Quantity', 'woocommerce');
    ?>
</th>
                <th class="product-total"><?php 
    _e('Total', 'woocommerce');
    ?>
</th>
            </tr>
            </thead>
            <tfoot>
            <?php 
    if ($totals = $order->get_order_item_totals()) {
        foreach ($totals as $total) {
            ?>
                        <tr>
                            <td class="filler-td">&nbsp;</td>
                            <th scope="row"><?php 
            echo $total['label'];
            ?>
</th>
                            <td class="product-total"><?php 
            echo $total['value'];
            ?>
</td>
                        </tr>
                    <?php 
        }
    }
    ?>
            </tfoot>
            <tbody>
            <?php 
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
            $item_meta = new WC_Order_Item_Meta($item['item_meta']);
            ?>
                        <tr class="<?php 
            echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order));
            ?>
">
                            <td class="product-name">
                        <span class="product-thumbnail">
                            <?php 
            $thumbnail = apply_filters('woocommerce_cart_item_thumbnail', $_product->get_image());
            if (!$_product->is_visible()) {
                echo $thumbnail;
            } else {
                printf('<a href="%s">%s</a>', $_product->get_permalink(), $thumbnail);
            }
            ?>
                        </span>

                                <div class="product-info">
                                    <?php 
            if ($_product && !$_product->is_visible()) {
                echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
            } else {
                echo apply_filters('woocommerce_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item);
            }
            $item_meta->display();
            if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
                $download_files = $order->get_item_downloads($item);
                $i = 0;
                $links = array();
                foreach ($download_files as $download_id => $file) {
                    $i++;
                    $links[] = '<small><a href="' . esc_url($file['download_url']) . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_files) > 1 ? ' ' . $i . ': ' : ': ') . esc_html($file['name']) . '</a></small>';
                }
                echo '<br/>' . implode('<br/>', $links);
            }
            ?>
                                </div>
                            </td>
                            <td class="product-quantity">
                                <?php 
            echo apply_filters('woocommerce_order_item_quantity_html', $item['qty'], $item);
            ?>
                            </td>
                            <td class="product-total">
                                <?php 
            echo $order->get_formatted_line_subtotal($item);
            ?>
                            </td>
                        </tr>
                        <?php 
            if (in_array($order->status, array('processing', 'completed')) && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
                ?>
                            <tr class="product-purchase-note">
                                <td colspan="3"><?php 
                echo apply_filters('the_content', $purchase_note);
                ?>
</td>
                            </tr>
                        <?php 
            }
        }
    }
    do_action('woocommerce_order_items_table', $order);
    ?>
            </tbody>
        </table>
        <?php 
    do_action('woocommerce_order_details_after_order_table', $order);
    ?>
    </div>

    <div class="avada-customer-details woocommerce-content-box full-width">
        <header>
            <h2><?php 
    _e('Customer details', 'woocommerce');
    ?>
</h2>
        </header>
        <dl class="customer_details">
            <?php 
    if ($order->billing_email) {
        echo '<dt>' . __('Email:', 'woocommerce') . '</dt> <dd>' . $order->billing_email . '</dd><br />';
    }
    if ($order->billing_phone) {
        echo '<dt>' . __('Telephone:', 'woocommerce') . '</dt> <dd>' . $order->billing_phone . '</dd>';
    }
    // Additional customer details hook
    do_action('woocommerce_order_details_after_customer_details', $order);
    ?>
        </dl>

        <?php 
    if (get_option('woocommerce_ship_to_billing_address_only') === 'no' && get_option('woocommerce_calc_shipping') !== 'no') {
        ?>

        <div class="col2-set addresses">

            <div class="col-1">

                <?php 
    }
    ?>

                <header class="title">
                    <h3><?php 
    _e('Billing Address', 'woocommerce');
    ?>
</h3>
                </header>
                <address><p>
                        <?php 
    if (!$order->get_formatted_billing_address()) {
        _e('N/A', 'woocommerce');
    } else {
        echo $order->get_formatted_billing_address();
    }
    ?>
                    </p></address>

                <?php 
    if (get_option('woocommerce_ship_to_billing_address_only') === 'no' && get_option('woocommerce_calc_shipping') !== 'no') {
        ?>

            </div>
            <!-- /.col-1 -->

            <div class="col-2">

                <header class="title">
                    <h3><?php 
        _e('Shipping Address', 'woocommerce');
        ?>
</h3>
                </header>
                <address><p>
                        <?php 
        if (!$order->get_formatted_shipping_address()) {
            _e('N/A', 'woocommerce');
        } else {
            echo $order->get_formatted_shipping_address();
        }
        ?>
                    </p></address>

            </div>
            <!-- /.col-2 -->

        </div>
        <!-- /.col2-set -->

    <?php 
    }
    ?>

        <div class="clear"></div>

    </div>

<?php 
}
Esempio n. 19
0
echo $column_width;
?>
"><?php 
_e('Price', 'woocommerce-germanized-pro');
?>
</th>
		</tr>
	</thead>
	<tbody>
		<?php 
if ($invoice->items) {
    ?>
			<?php 
    foreach ($invoice->items as $item) {
        $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
        $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
        $item_meta_print = '';
        if ($item_meta->meta) {
            $item_meta_print = $item_meta->display(true, true, '_', ", ");
        }
        ?>
				<tr class="data" nobr="true">
					<td class="first" width="<?php 
        echo $first_width;
        ?>
">
						<?php 
        echo $item['name'];
        ?>
 
						<?php 
 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
 /**
  * Prepare a single order output for response.
  *
  * @param WP_Post $post Post object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response $data
  */
 public function prepare_item_for_response($post, $request)
 {
     global $wpdb;
     $order = wc_get_order($post);
     $dp = $request['dp'];
     $data = array('id' => $order->id, 'parent_id' => $post->post_parent, 'status' => $order->get_status(), 'order_key' => $order->order_key, 'currency' => $order->get_order_currency(), 'version' => $order->order_version, 'prices_include_tax' => $order->prices_include_tax, 'date_created' => wc_rest_prepare_date_response($post->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($post->post_modified_gmt), 'customer_id' => $order->get_user_id(), 'discount_total' => wc_format_decimal($order->get_total_discount(), $dp), 'discount_tax' => wc_format_decimal($order->cart_discount_tax, $dp), 'shipping_total' => wc_format_decimal($order->get_total_shipping(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'total' => wc_format_decimal($order->get_total(), $dp), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'billing' => array(), 'shipping' => array(), 'payment_method' => $order->payment_method, 'payment_method_title' => $order->payment_method_title, 'transaction_id' => $order->get_transaction_id(), 'customer_ip_address' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'created_via' => $order->created_via, 'customer_note' => $order->customer_note, 'date_completed' => wc_rest_prepare_date_response($order->completed_date), 'date_paid' => $order->paid_date, 'cart_hash' => $order->cart_hash, 'line_items' => array(), 'tax_lines' => array(), 'shipping_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array(), 'refunds' => array());
     // Add addresses.
     $data['billing'] = $order->get_address('billing');
     $data['shipping'] = $order->get_address('shipping');
     // Add line items.
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = 0;
         $variation_id = 0;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = $product->id;
             $variation_id = $product->variation_id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         $hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
         foreach ($meta->get_formatted($hideprefix) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $formatted_meta['key'], 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $line_item = array('id' => $item_id, 'name' => $item['name'], 'sku' => $product_sku, 'product_id' => (int) $product_id, 'variation_id' => (int) $variation_id, 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : '', 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'taxes' => array(), 'meta' => $item_meta);
         $item_line_taxes = maybe_unserialize($item['line_tax_data']);
         if (isset($item_line_taxes['total'])) {
             $line_tax = array();
             foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) {
                 $line_tax[$tax_rate_id] = array('id' => $tax_rate_id, 'total' => $tax, 'subtotal' => '');
             }
             foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) {
                 $line_tax[$tax_rate_id]['subtotal'] = $tax;
             }
             $line_item['taxes'] = array_values($line_tax);
         }
         $data['line_items'][] = $line_item;
     }
     // Add taxes.
     foreach ($order->get_items('tax') as $key => $tax) {
         $tax_line = array('id' => $key, 'rate_code' => $tax['name'], 'rate_id' => $tax['rate_id'], 'label' => isset($tax['label']) ? $tax['label'] : $tax['name'], 'compound' => (bool) $tax['compound'], 'tax_total' => wc_format_decimal($tax['tax_amount'], $dp), 'shipping_tax_total' => wc_format_decimal($tax['shipping_tax_amount'], $dp));
         $data['tax_lines'][] = $tax_line;
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $shipping_line = array('id' => $shipping_item_id, 'method_title' => $shipping_item['name'], 'method_id' => $shipping_item['method_id'], 'total' => wc_format_decimal($shipping_item['cost'], $dp), 'total_tax' => wc_format_decimal('', $dp), 'taxes' => array());
         $shipping_taxes = maybe_unserialize($shipping_item['taxes']);
         if (!empty($shipping_taxes)) {
             $shipping_line['total_tax'] = wc_format_decimal(array_sum($shipping_taxes), $dp);
             foreach ($shipping_taxes as $tax_rate_id => $tax) {
                 $shipping_line['taxes'][] = array('id' => $tax_rate_id, 'total' => $tax);
             }
         }
         $data['shipping_lines'][] = $shipping_line;
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $fee_line = array('id' => $fee_item_id, 'name' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : '', 'tax_status' => 'taxable', 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp), 'taxes' => array());
         $fee_line_taxes = maybe_unserialize($fee_item['line_tax_data']);
         if (isset($fee_line_taxes['total'])) {
             $fee_tax = array();
             foreach ($fee_line_taxes['total'] as $tax_rate_id => $tax) {
                 $fee_tax[$tax_rate_id] = array('id' => $tax_rate_id, 'total' => $tax, 'subtotal' => '');
             }
             foreach ($fee_line_taxes['subtotal'] as $tax_rate_id => $tax) {
                 $fee_tax[$tax_rate_id]['subtotal'] = $tax;
             }
             $fee_line['taxes'] = array_values($fee_tax);
         }
         $data['fee_lines'][] = $fee_line;
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $coupon_line = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'discount' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'discount_tax' => wc_format_decimal($coupon_item['discount_amount_tax'], $dp));
         $data['coupon_lines'][] = $coupon_line;
     }
     // Add refunds.
     foreach ($order->get_refunds() as $refund) {
         $data['refunds'][] = array('id' => $refund->id, 'refund' => $refund->get_refund_reason() ? $refund->get_refund_reason() : '', 'total' => '-' . wc_format_decimal($refund->get_refund_amount(), $dp));
     }
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($order));
     /**
      * Filter the data for a response.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for the response.
      *
      * @param WP_REST_Response   $response   The response object.
      * @param WP_Post            $post       Post object.
      * @param WP_REST_Request    $request    Request object.
      */
     return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request);
 }
Esempio n. 22
0
/**
 * Email Order Items (plain)
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates/Emails/Plain
 * @version     2.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce;
foreach ($items as $item) {
    // Get/prep product data
    $_product = $order->get_product_from_item($item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta']);
    // Title, sku, qty, price
    echo apply_filters('woocommerce_order_product_title', $item['name'], $_product);
    echo $show_sku && $_product->get_sku() ? ' (#' . $_product->get_sku() . ')' : '';
    // Variation
    echo $item_meta->meta ? "\n" . nl2br($item_meta->display(true, true)) : '';
    // Quantity
    echo "\n" . sprintf(__('Quantity: %s', 'woocommerce'), $item['qty']);
    // Cost
    echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item));
    // Download URLs
    if ($show_download_links && $_product->exists() && $_product->is_downloadable()) {
        echo "\n" . implode("\n", $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item));
    }
    // Note
    if ($show_purchase_note && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
Esempio n. 23
0
 public function __construct()
 {
     //_deprecated_function( 'order_item_meta', '1.6.4', 'WC_Order_Item_Meta()' );
     parent::__construct();
 }
Esempio n. 24
0
 /**
  * Get the current order items
  */
 public function get_order_items()
 {
     global $woocommerce;
     global $_product;
     $items = $this->order->get_items();
     $data_list = array();
     if (sizeof($items) > 0) {
         foreach ($items as $item) {
             // Array with data for the pdf template
             $data = array();
             // Set the id
             $data['product_id'] = $item['product_id'];
             $data['variation_id'] = $item['variation_id'];
             // Set item name
             $data['name'] = $item['name'];
             // Set item quantity
             $data['quantity'] = $item['qty'];
             // Set the line total (=after discount)
             $quantity_divider = $item['qty'] == 0 ? 1 : $item['qty'];
             // prevent division by zero
             $data['line_total'] = $this->wc_price($item['line_total']);
             $data['single_line_total'] = $this->wc_price($item['line_total'] / $quantity_divider);
             $data['line_tax'] = $this->wc_price($item['line_tax']);
             $data['single_line_tax'] = $this->wc_price($item['line_tax'] / $quantity_divider);
             $data['tax_rates'] = $this->get_tax_rate($item['tax_class'], $item['line_total'], $item['line_tax']);
             // Set the line subtotal (=before discount)
             $data['line_subtotal'] = $this->wc_price($item['line_subtotal']);
             $data['line_subtotal_tax'] = $this->wc_price($item['line_subtotal_tax']);
             $data['ex_price'] = $this->get_formatted_item_price($item, 'total', 'excl');
             $data['price'] = $this->get_formatted_item_price($item, 'total');
             $data['order_price'] = $this->order->get_formatted_line_subtotal($item);
             // formatted according to WC settings
             // Calculate the single price with the same rules as the formatted line subtotal (!)
             // = before discount
             $data['ex_single_price'] = $this->get_formatted_item_price($item, 'single', 'excl');
             $data['single_price'] = $this->get_formatted_item_price($item, 'single');
             // Set item meta and replace it when it is empty
             $meta = new WC_Order_Item_Meta($item['item_meta']);
             $data['meta'] = $meta->display(false, true);
             // Pass complete item array
             $data['item'] = $item;
             // Create the product to display more info
             $data['product'] = null;
             $product = $this->order->get_product_from_item($item);
             // Checking fo existance, thanks to MDesigner0
             if (!empty($product)) {
                 // Set the thumbnail id
                 $data['thumbnail_id'] = $this->get_thumbnail_id($product->id);
                 // Set the thumbnail server path
                 $data['thumbnail_path'] = get_attached_file($data['thumbnail_id']);
                 // Thumbnail (full img tag)
                 if (apply_filters('wpo_wcpdf_use_path', true)) {
                     // load img with server path by default
                     $data['thumbnail'] = sprintf('<img width="90" height="90" src="%s" class="attachment-shop_thumbnail wp-post-image">', $data['thumbnail_path']);
                 } else {
                     // load img with http url when filtered
                     $data['thumbnail'] = $product->get_image('shop_thumbnail', array('title' => ''));
                 }
                 // Set the single price (turned off to use more consistent calculated price)
                 // $data['single_price'] = woocommerce_price ( $product->get_price() );
                 // Set item SKU
                 $data['sku'] = $product->get_sku();
                 // Set item weight
                 $data['weight'] = $product->get_weight();
                 // Set item dimensions
                 $data['dimensions'] = $product->get_dimensions();
                 // Pass complete product object
                 $data['product'] = $product;
             }
             $data_list[] = apply_filters('wpo_wcpdf_order_item_data', $data);
         }
     }
     return apply_filters('wpo_wcpdf_order_items_data', $data_list);
 }
/**
 * Email Order Items
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates/Emails
 * @version     2.0.3
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce;
foreach ($items as $item) {
    // Get/prep product data
    $_product = $order->get_product_from_item($item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta']);
    $image = $show_image ? '<img src="' . current(wp_get_attachment_image_src(get_post_thumbnail_id($_product->id), 'thumbnail')) . '" alt="Product Image" height="' . $image_size[1] . '" width="' . $image_size[0] . '" style="vertical-align:middle; margin-right: 10px;" />' : '';
    ?>
	<tr>
		<td style="text-align:left; vertical-align:middle; border: 1px solid #eee; word-wrap:break-word;"><?php 
    // Show title/image etc
    echo apply_filters('woocommerce_order_product_image', $image, $_product, $show_image);
    // Product name
    echo apply_filters('woocommerce_order_product_title', $item['name'], $_product);
    // SKU
    echo $show_sku && $_product->get_sku() ? ' (#' . $_product->get_sku() . ')' : '';
    // File URLs
    if ($show_download_links && $_product->exists() && $_product->is_downloadable()) {
        $download_file_urls = $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item);
        $i = 0;
        foreach ($download_file_urls as $file_url => $download_file_url) {
        /**
         * Output custom columns for coupons
         * @param  string $column
         */
        public function render_shop_order_columns($column)
        {
            global $post, $woocommerce, $the_order;
            if (empty($the_order) || $the_order->id != $post->ID) {
                $the_order = wc_get_order($post->ID);
            }
            switch ($column) {
                case 'order_status':
                    printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->get_status()), wc_get_order_status_name($the_order->get_status()), wc_get_order_status_name($the_order->get_status()));
                    break;
                case 'order_date':
                    if ('0000-00-00 00:00:00' == $post->post_date) {
                        $t_time = $h_time = __('Unpublished', 'woocommerce');
                    } else {
                        $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
                        $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post);
                    }
                    echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>';
                    break;
                case 'customer_message':
                    if ($the_order->customer_message) {
                        echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>';
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'order_items':
                    echo '<a href="#" class="show_order_items">' . apply_filters('woocommerce_admin_order_item_count', sprintf(_n('%d item', '%d items', $the_order->get_item_count(), 'woocommerce'), $the_order->get_item_count()), $the_order) . '</a>';
                    if (sizeof($the_order->get_items()) > 0) {
                        echo '<table class="order_items" cellspacing="0">';
                        foreach ($the_order->get_items() as $item) {
                            $product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item);
                            $item_meta = new WC_Order_Item_Meta($item, $product);
                            $item_meta_html = $item_meta->display(true, true);
                            ?>
						<tr class="<?php 
                            echo apply_filters('woocommerce_admin_order_item_class', '', $item);
                            ?>
">
							<td class="qty"><?php 
                            echo absint($item['qty']);
                            ?>
</td>
							<td class="name">
								<?php 
                            if ($product) {
                                ?>
									<?php 
                                echo wc_product_sku_enabled() && $product->get_sku() ? $product->get_sku() . ' - ' : '';
                                ?>
<a href="<?php 
                                echo get_edit_post_link($product->id);
                                ?>
" title="<?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
"><?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
</a>
								<?php 
                            } else {
                                ?>
									<?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
								<?php 
                            }
                            ?>
								<?php 
                            if (!empty($item_meta_html)) {
                                ?>
									<a class="tips" href="#" data-tip="<?php 
                                echo esc_attr($item_meta_html);
                                ?>
">[?]</a>
								<?php 
                            }
                            ?>
							</td>
						</tr>
						<?php 
                        }
                        echo '</table>';
                    } else {
                        echo '&ndash;';
                    }
                    break;
                case 'shipping_address':
                    if ($address = $the_order->get_formatted_shipping_address()) {
                        echo '<a target="_blank" href="' . esc_url($the_order->get_shipping_address_map_url()) . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $address)) . '</a>';
                    } else {
                        echo '&ndash;';
                    }
                    if ($the_order->get_shipping_method()) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>';
                    }
                    break;
                case 'order_notes':
                    if ($post->comment_count) {
                        // check the status of the post
                        $status = 'trash' !== $post->post_status ? '' : 'post-trashed';
                        $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status));
                        $latest_note = current($latest_notes);
                        if ($post->comment_count == 1) {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>';
                        } elseif (isset($latest_note->comment_content)) {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content . '<br/><small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') . '">' . __('Yes', 'woocommerce') . '</span>';
                        } else {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip(sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count)) . '">' . __('Yes', 'woocommerce') . '</span>';
                        }
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'order_total':
                    echo $the_order->get_formatted_order_total();
                    if ($the_order->payment_method_title) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>';
                    }
                    break;
                case 'order_title':
                    $customer_tip = array();
                    if ($address = $the_order->get_formatted_billing_address()) {
                        $customer_tip[] = __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>';
                    }
                    if ($the_order->billing_phone) {
                        $customer_tip[] = __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone;
                    }
                    if ($the_order->user_id) {
                        $user_info = get_userdata($the_order->user_id);
                    }
                    if (!empty($user_info)) {
                        $username = '******' . absint($user_info->ID) . '">';
                        if ($user_info->first_name || $user_info->last_name) {
                            $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name));
                        } else {
                            $username .= esc_html(ucfirst($user_info->display_name));
                        }
                        $username .= '</a>';
                    } else {
                        if ($the_order->billing_first_name || $the_order->billing_last_name) {
                            $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name);
                        } else {
                            $username = __('Guest', 'woocommerce');
                        }
                    }
                    printf(_x('%s by %s', 'Order number by X', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '" class="row-title"><strong>#' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username);
                    if ($the_order->billing_email) {
                        echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>';
                    }
                    echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'woocommerce') . '</span></button>';
                    break;
                case 'order_actions':
                    ?>
<p>
					<?php 
                    do_action('woocommerce_admin_order_actions_start', $the_order);
                    $actions = array();
                    if ($the_order->has_status(array('pending', 'on-hold'))) {
                        $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing");
                    }
                    if ($the_order->has_status(array('pending', 'on-hold', 'processing'))) {
                        $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete");
                    }
                    $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view");
                    $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order);
                    foreach ($actions as $action) {
                        printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                    }
                    do_action('woocommerce_admin_order_actions_end', $the_order);
                    ?>
				</p><?php 
                    break;
            }
        }
 /**
  * Get PayPal Args for passing to PP
  *
  * @access public
  * @param mixed $order
  * @return array
  */
 function get_paypal_args($order)
 {
     global $woocommerce;
     $order_id = $order->id;
     if ('yes' == $this->debug) {
         $this->log->add('paypal', 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url);
     }
     if (in_array($order->billing_country, array('US', 'CA'))) {
         $order->billing_phone = str_replace(array('( ', '-', ' ', ' )', '.'), '', $order->billing_phone);
         $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
     } else {
         $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
     }
     // PayPal Args
     $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->email, 'no_note' => 1, 'currency_code' => get_woocommerce_currency(), 'charset' => 'UTF-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => add_query_arg('utm_nooverride', '1', $this->get_return_url($order)), 'cancel_return' => $order->get_cancel_order_url(), 'page_style' => $this->page_style, 'BUTTONSOURCE' => 'WooThemes_Cart', 'invoice' => $this->invoice_prefix . ltrim($order->get_order_number(), '#'), 'custom' => serialize(array($order_id, $order->order_key)), 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email), $phone_args);
     // Shipping
     if ($this->send_shipping == 'yes') {
         $paypal_args['address_override'] = $this->address_override == 'yes' ? 1 : 0;
         $paypal_args['no_shipping'] = 0;
         // If we are sending shipping, send shipping address instead of billing
         $paypal_args['first_name'] = $order->shipping_first_name;
         $paypal_args['last_name'] = $order->shipping_last_name;
         $paypal_args['company'] = $order->shipping_company;
         $paypal_args['address1'] = $order->shipping_address_1;
         $paypal_args['address2'] = $order->shipping_address_2;
         $paypal_args['city'] = $order->shipping_city;
         $paypal_args['state'] = $order->shipping_state;
         $paypal_args['country'] = $order->shipping_country;
         $paypal_args['zip'] = $order->shipping_postcode;
     } else {
         $paypal_args['no_shipping'] = 1;
     }
     // If prices include tax or have order discounts, send the whole order as a single item
     if (get_option('woocommerce_prices_include_tax') == 'yes' || $order->get_order_discount() > 0 || sizeof($order->get_items()) + sizeof($order->get_fees()) >= 9) {
         // Discount
         $paypal_args['discount_amount_cart'] = $order->get_order_discount();
         // Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall
         $item_names = array();
         if (sizeof($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_names[] = $item['name'] . ' x ' . $item['qty'];
                 }
             }
         }
         $paypal_args['item_name_1'] = sprintf(__('Order %s', 'woocommerce'), $order->get_order_number()) . " - " . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->get_total() - $order->get_shipping() - $order->get_shipping_tax() + $order->get_order_discount(), 2, '.', '');
         // Shipping Cost
         // No longer using shipping_1 because
         //		a) paypal ignore it if *any* shipping rules are within paypal
         //		b) paypal ignore anything over 5 digits, so 999.99 is the max
         // $paypal_args['shipping_1']		= number_format( $order->get_shipping() + $order->get_shipping_tax() , 2, '.', '' );
         if ($order->get_shipping() + $order->get_shipping_tax() > 0) {
             $paypal_args['item_name_2'] = __('Shipping via', 'woocommerce') . ' ' . ucwords($order->shipping_method_title);
             $paypal_args['quantity_2'] = '1';
             $paypal_args['amount_2'] = number_format($order->get_shipping() + $order->get_shipping_tax(), 2, '.', '');
         }
     } else {
         // Tax
         $paypal_args['tax_cart'] = $order->get_total_tax();
         // Cart Contents
         $item_loop = 0;
         if (sizeof($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_loop++;
                     $product = $order->get_product_from_item($item);
                     $item_name = $item['name'];
                     $item_meta = new WC_Order_Item_Meta($item['item_meta']);
                     if ($meta = $item_meta->display(true, true)) {
                         $item_name .= ' ( ' . $meta . ' )';
                     }
                     $paypal_args['item_name_' . $item_loop] = html_entity_decode($item_name, ENT_NOQUOTES, 'UTF-8');
                     $paypal_args['quantity_' . $item_loop] = $item['qty'];
                     $paypal_args['amount_' . $item_loop] = $order->get_item_subtotal($item, false);
                     if ($product->get_sku()) {
                         $paypal_args['item_number_' . $item_loop] = $product->get_sku();
                     }
                 }
             }
         }
         // Discount
         if ($order->get_cart_discount() > 0) {
             $paypal_args['discount_amount_cart'] = round($order->get_cart_discount(), 2);
         }
         // Fees
         if (sizeof($order->get_fees()) > 0) {
             foreach ($order->get_fees() as $item) {
                 $item_loop++;
                 $paypal_args['item_name_' . $item_loop] = $item['name'];
                 $paypal_args['quantity_' . $item_loop] = 1;
                 $paypal_args['amount_' . $item_loop] = $item['line_total'];
             }
         }
         // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
         if ($order->get_shipping() > 0) {
             $item_loop++;
             $paypal_args['item_name_' . $item_loop] = __('Shipping via', 'woocommerce') . ' ' . ucwords($order->shipping_method_title);
             $paypal_args['quantity_' . $item_loop] = '1';
             $paypal_args['amount_' . $item_loop] = number_format($order->get_shipping(), 2, '.', '');
         }
     }
     $paypal_args = apply_filters('woocommerce_paypal_args', $paypal_args);
     return $paypal_args;
 }
Esempio n. 28
0
<?php
/**
 * Email Order Items (plain)
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates/Emails/Plain
 * @version     2.1.2
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

foreach ( $items as $item_id => $item ) :
	$_product     = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
	$item_meta    = new WC_Order_Item_Meta( $item, $_product );

	if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {

		// Title
		echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );

		// SKU
		if ( $show_sku && $_product->get_sku() ) {
			echo ' (#' . $_product->get_sku() . ')';
		}

		// allow other plugins to add additional product information here
		do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );

		// Variation
Esempio n. 29
0
<?php

/**
 * Email Order Items (plain)
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates/Emails/Plain
 * @version     2.1.2
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
foreach ($items as $item_id => $item) {
    $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
    // Title
    echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
    // SKU
    if ($show_sku && $_product->get_sku()) {
        echo ' (#' . $_product->get_sku() . ')';
    }
    // allow other plugins to add additional product information here
    do_action('woocommerce_order_item_meta_start', $item_id, $item, $order);
    // Variation
    echo $item_meta->meta ? "\n" . $item_meta->display(true, true) : '';
    // Quantity
    echo "\n" . sprintf(__('Quantity: %s', 'woocommerce'), $item['qty']);
    // Cost
    echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item));
    // Download URLs
Esempio n. 30
0
/**
 * Save the order data meta box.
 *
 * @access public
 * @param mixed $post_id
 * @param mixed $post
 * @return void
 */
function woocommerce_process_shop_order_meta($post_id, $post)
{
    global $wpdb, $woocommerce, $woocommerce_errors;
    // Add key
    add_post_meta($post_id, '_order_key', uniqid('order_'), true);
    // Update post data
    update_post_meta($post_id, '_billing_first_name', stripslashes($_POST['_billing_first_name']));
    update_post_meta($post_id, '_billing_last_name', stripslashes($_POST['_billing_last_name']));
    update_post_meta($post_id, '_billing_company', stripslashes($_POST['_billing_company']));
    update_post_meta($post_id, '_billing_address_1', stripslashes($_POST['_billing_address_1']));
    update_post_meta($post_id, '_billing_address_2', stripslashes($_POST['_billing_address_2']));
    update_post_meta($post_id, '_billing_city', stripslashes($_POST['_billing_city']));
    update_post_meta($post_id, '_billing_postcode', stripslashes($_POST['_billing_postcode']));
    update_post_meta($post_id, '_billing_country', stripslashes($_POST['_billing_country']));
    update_post_meta($post_id, '_billing_state', stripslashes($_POST['_billing_state']));
    update_post_meta($post_id, '_billing_email', stripslashes($_POST['_billing_email']));
    update_post_meta($post_id, '_billing_phone', stripslashes($_POST['_billing_phone']));
    update_post_meta($post_id, '_shipping_first_name', stripslashes($_POST['_shipping_first_name']));
    update_post_meta($post_id, '_shipping_last_name', stripslashes($_POST['_shipping_last_name']));
    update_post_meta($post_id, '_shipping_company', stripslashes($_POST['_shipping_company']));
    update_post_meta($post_id, '_shipping_address_1', stripslashes($_POST['_shipping_address_1']));
    update_post_meta($post_id, '_shipping_address_2', stripslashes($_POST['_shipping_address_2']));
    update_post_meta($post_id, '_shipping_city', stripslashes($_POST['_shipping_city']));
    update_post_meta($post_id, '_shipping_postcode', stripslashes($_POST['_shipping_postcode']));
    update_post_meta($post_id, '_shipping_country', stripslashes($_POST['_shipping_country']));
    update_post_meta($post_id, '_shipping_state', stripslashes($_POST['_shipping_state']));
    update_post_meta($post_id, '_order_shipping', stripslashes($_POST['_order_shipping']));
    update_post_meta($post_id, '_cart_discount', stripslashes($_POST['_cart_discount']));
    update_post_meta($post_id, '_order_discount', stripslashes($_POST['_order_discount']));
    update_post_meta($post_id, '_order_total', stripslashes($_POST['_order_total']));
    update_post_meta($post_id, '_customer_user', (int) $_POST['customer_user']);
    update_post_meta($post_id, '_order_tax', stripslashes($_POST['_order_tax']));
    update_post_meta($post_id, '_order_shipping_tax', stripslashes($_POST['_order_shipping_tax']));
    // Shipping method handling
    if (get_post_meta($post_id, '_shipping_method', true) !== stripslashes($_POST['_shipping_method'])) {
        $shipping_method = esc_attr(trim(stripslashes($_POST['_shipping_method'])));
        update_post_meta($post_id, '_shipping_method', $shipping_method);
    }
    if (get_post_meta($post_id, '_shipping_method_title', true) !== stripslashes($_POST['_shipping_method_title'])) {
        $shipping_method_title = esc_attr(trim(stripslashes($_POST['_shipping_method_title'])));
        if (!$shipping_method_title) {
            $shipping_method = esc_attr($_POST['_shipping_method']);
            $methods = $woocommerce->shipping->load_shipping_methods();
            if (isset($methods) && isset($methods[$shipping_method])) {
                $shipping_method_title = $methods[$shipping_method]->get_title();
            }
        }
        update_post_meta($post_id, '_shipping_method_title', $shipping_method_title);
    }
    // Payment method handling
    if (get_post_meta($post_id, '_payment_method', true) !== stripslashes($_POST['_payment_method'])) {
        $methods = $woocommerce->payment_gateways->payment_gateways();
        $payment_method = esc_attr($_POST['_payment_method']);
        $payment_method_title = $payment_method;
        if (isset($methods) && isset($methods[$payment_method])) {
            $payment_method_title = $methods[$payment_method]->get_title();
        }
        update_post_meta($post_id, '_payment_method', $payment_method);
        update_post_meta($post_id, '_payment_method_title', $payment_method_title);
    }
    // Update date
    if (empty($_POST['order_date'])) {
        $date = current_time('timestamp');
    } else {
        $date = strtotime($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
    }
    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_date = %s WHERE ID = %s", date_i18n('Y-m-d H:i:s', $date), $post_id));
    // Tax rows
    $order_taxes = array();
    if (isset($_POST['_order_taxes_label'])) {
        $order_taxes_label = $_POST['_order_taxes_label'];
        $order_taxes_compound = isset($_POST['_order_taxes_compound']) ? $_POST['_order_taxes_compound'] : array();
        $order_taxes_cart = $_POST['_order_taxes_cart'];
        $order_taxes_shipping = $_POST['_order_taxes_shipping'];
        $order_taxes_label_count = sizeof($order_taxes_label);
        for ($i = 0; $i < $order_taxes_label_count; $i++) {
            // Add to array if the tax amount is set
            if (!$order_taxes_cart[$i] && !$order_taxes_shipping[$i]) {
                continue;
            }
            if (!$order_taxes_label[$i]) {
                $order_taxes_label[$i] = $woocommerce->countries->tax_or_vat();
            }
            if (isset($order_taxes_compound[$i])) {
                $is_compound = 1;
            } else {
                $is_compound = 0;
            }
            $order_taxes[] = array('label' => esc_attr($order_taxes_label[$i]), 'compound' => $is_compound, 'cart_tax' => esc_attr($order_taxes_cart[$i]), 'shipping_tax' => esc_attr($order_taxes_shipping[$i]));
        }
    }
    update_post_meta($post_id, '_order_taxes', $order_taxes);
    // Order items
    $order_items = array();
    if (isset($_POST['item_id'])) {
        $item_id = $_POST['item_id'];
        $item_variation = $_POST['item_variation'];
        $item_name = $_POST['item_name'];
        $item_quantity = $_POST['item_quantity'];
        $line_subtotal = $_POST['line_subtotal'];
        $line_subtotal_tax = $_POST['line_subtotal_tax'];
        $line_total = $_POST['line_total'];
        $line_tax = $_POST['line_tax'];
        $item_meta_names = isset($_POST['meta_name']) ? $_POST['meta_name'] : '';
        $item_meta_values = isset($_POST['meta_value']) ? $_POST['meta_value'] : '';
        $item_tax_class = $_POST['item_tax_class'];
        $item_id_count = sizeof($item_id);
        for ($i = 0; $i < $item_id_count; $i++) {
            if (!isset($item_id[$i]) || !$item_id[$i]) {
                continue;
            }
            if (!isset($item_name[$i])) {
                continue;
            }
            if (!isset($item_quantity[$i]) || $item_quantity[$i] < 1) {
                continue;
            }
            if (!isset($line_total[$i])) {
                continue;
            }
            if (!isset($line_tax[$i])) {
                continue;
            }
            // Meta
            $item_meta = new WC_Order_Item_Meta();
            if (isset($item_meta_names[$i]) && isset($item_meta_values[$i])) {
                $meta_names = $item_meta_names[$i];
                $meta_values = $item_meta_values[$i];
                $meta_names_count = sizeof($meta_names);
                for ($ii = 0; $ii < $meta_names_count; $ii++) {
                    $meta_name = esc_attr($meta_names[$ii]);
                    $meta_value = esc_attr($meta_values[$ii]);
                    if ($meta_name && $meta_value) {
                        $item_meta->add($meta_name, $meta_value);
                    }
                }
            }
            // Add to array
            $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => (int) $item_variation[$i], 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', ''), '0'), '.'), 'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', ''), '0'), '.'), 'item_meta' => $item_meta->meta, 'tax_class' => woocommerce_clean($item_tax_class[$i])));
        }
    }
    update_post_meta($post_id, '_order_items', $order_items);
    // Order data saved, now get it so we can manipulate status
    $order = new WC_Order($post_id);
    // Order status
    $order->update_status($_POST['order_status']);
    // Handle button actions
    if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && sizeof($order_items) > 0) {
        $order->add_order_note(__('Manually reducing stock.', 'woocommerce'));
        foreach ($order_items as $order_item) {
            $_product = $order->get_product_from_item($order_item);
            if ($_product->exists()) {
                if ($_product->managing_stock()) {
                    $old_stock = $_product->stock;
                    $new_quantity = $_product->reduce_stock($order_item['qty']);
                    $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'woocommerce'), $order_item['id'], $old_stock, $new_quantity));
                    $order->send_stock_notifications($_product, $new_quantity, $order_item['qty']);
                }
            } else {
                $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'woocommerce'), $order_item['id'], $order_item['name']));
            }
        }
        $order->add_order_note(__('Manual stock reduction complete.', 'woocommerce'));
        do_action('woocommerce_reduce_order_stock', $order);
    } elseif (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) {
        $order->add_order_note(__('Manually restoring stock.', 'woocommerce'));
        foreach ($order_items as $order_item) {
            $_product = $order->get_product_from_item($order_item);
            if ($_product->exists()) {
                if ($_product->managing_stock()) {
                    $old_stock = $_product->stock;
                    $new_quantity = $_product->increase_stock($order_item['qty']);
                    $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'woocommerce'), $order_item['id'], $old_stock, $new_quantity));
                }
            } else {
                $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'woocommerce'), $order_item['id'], $order_item['name']));
            }
        }
        $order->add_order_note(__('Manual stock restore complete.', 'woocommerce'));
        do_action('woocommerce_restore_order_stock', $order);
    } elseif (isset($_POST['invoice']) && $_POST['invoice']) {
        do_action('woocommerce_before_send_customer_invoice', $order);
        $mailer = $woocommerce->mailer();
        $mailer->customer_invoice($order);
        do_action('woocommerce_after__customer_invoice', $order);
    }
    delete_transient('woocommerce_processing_order_count');
}