/**
  * Add a "Change Shipping Address" button to the "My Subscriptions" table for those subscriptions
  * which require shipping.
  *
  * @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
  * @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
  * @since 1.3
  */
 public static function add_edit_address_subscription_action($all_actions, $subscriptions)
 {
     foreach ($all_actions as $subscription_key => $actions) {
         $order = new WC_Order($subscriptions[$subscription_key]['order_id']);
         $needs_shipping = false;
         foreach ($order->get_items() as $item) {
             if ($item['product_id'] !== $subscriptions[$subscription_key]['product_id']) {
                 continue;
             }
             $product = $order->get_product_from_item($item);
             if (!is_object($product)) {
                 // In case a product has been deleted
                 continue;
             }
             if ($product->needs_shipping()) {
                 $needs_shipping = true;
             }
         }
         if ($needs_shipping && in_array($subscriptions[$subscription_key]['status'], array('active', 'on-hold'))) {
             // WC 2.1+
             if (function_exists('wc_get_endpoint_url')) {
                 $all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('subscription' => $subscription_key), wc_get_endpoint_url('edit-address', 'shipping')), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
             } else {
                 $all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('address' => 'shipping', 'subscription' => $subscription_key), get_permalink(woocommerce_get_page_id('edit_address'))), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
             }
         }
     }
     return $all_actions;
 }
 /**
  * Complete virtual booking orders
  */
 public function complete_order($order_status, $order_id)
 {
     $order = new WC_Order($order_id);
     if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) {
         $virtual_booking_order = null;
         if (count($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ('line_item' == $item['type']) {
                     $_product = $order->get_product_from_item($item);
                     if (!$_product->is_virtual() || !$_product->is_type('booking')) {
                         // once we've found one non-virtual product we know we're done, break out of the loop
                         $virtual_booking_order = false;
                         break;
                     } else {
                         $virtual_booking_order = true;
                     }
                 }
             }
         }
         // virtual order, mark as completed
         if ($virtual_booking_order) {
             return 'completed';
         }
     }
     // non-virtual order, return original status
     return $order_status;
 }
 /**
  * Shipstation compatibility:
  *
  * When returning a single container item, add bundled items as metadata.
  *
  * @param  array    $items
  * @param  WC_Order $order
  * @return array
  */
 function order_add_composited_meta($items, $order)
 {
     global $wp;
     if (isset($wp->query_vars['wc-api']) && $wp->query_vars['wc-api'] === 'wc_shipstation') {
         foreach ($items as $item_id => $item) {
             if (isset($item['composite_children']) && isset($item['composite_cart_key']) && isset($item['per_product_shipping']) && $item['per_product_shipping'] === 'no') {
                 $bundle_key = $item['composite_cart_key'];
                 $meta_key = __('Contents', 'woocommerce-composite-products');
                 $meta_value = '';
                 foreach ($items as $child_item) {
                     if (isset($child_item['composite_parent']) && $child_item['composite_parent'] === $bundle_key) {
                         $child = $order->get_product_from_item($child_item);
                         if ($child && ($sku = $child->get_sku())) {
                             $sku .= ' – ';
                         } else {
                             $sku = '#' . (isset($child->variation_id) ? $child->variation_id : $child->id) . ' – ';
                         }
                         $meta_value .= $sku . $child_item['name'];
                         if (!empty($child_item['item_meta'][__('Part of', 'woocommerce-composite-products')])) {
                             unset($child_item['item_meta'][__('Part of', 'woocommerce-composite-products')]);
                         }
                         $item_meta = new WC_Order_Item_Meta($child_item['item_meta']);
                         $formatted_meta = $item_meta->display(true, true, '_', ', ');
                         if ($formatted_meta) {
                             $meta_value .= ' (' . $formatted_meta . ')';
                         }
                         $meta_value .= ' × ' . $child_item['qty'] . ', ';
                     }
                 }
                 $items[$item_id]['item_meta'][$meta_key] = rtrim($meta_value, ', ');
             }
         }
     }
     return $items;
 }
 public function is_available()
 {
     $order = null;
     if (!WC()->cart->needs_shipping()) {
         return false;
     }
     if (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) {
         $order_id = absint(get_query_var('order-pay'));
         $order = new WC_Order($order_id);
         // Test if order needs shipping.
         $needs_shipping = false;
         if (0 < sizeof($order->get_items())) {
             foreach ($order->get_items() as $item) {
                 $_product = $order->get_product_from_item($item);
                 if ($_product->needs_shipping()) {
                     $needs_shipping = true;
                     break;
                 }
             }
         }
         $needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping);
         if ($needs_shipping) {
             return false;
         }
     }
     if (!empty($this->enable_for_methods)) {
         // Only apply if all packages are being shipped via local pickup
         $chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods');
         if (isset($chosen_shipping_methods_session)) {
             $chosen_shipping_methods = array_unique($chosen_shipping_methods_session);
         } else {
             $chosen_shipping_methods = array();
         }
         $check_method = false;
         if (is_object($order)) {
             if ($order->shipping_method) {
                 $check_method = $order->shipping_method;
             }
         } elseif (empty($chosen_shipping_methods) || sizeof($chosen_shipping_methods) > 1) {
             $check_method = false;
         } elseif (sizeof($chosen_shipping_methods) == 1) {
             $check_method = $chosen_shipping_methods[0];
         }
         if (!$check_method) {
             return false;
         }
         $found = false;
         foreach ($this->enable_for_methods as $method_id) {
             if (strpos($check_method, $method_id) === 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             return false;
         }
     }
     return parent::is_available();
 }
 public function callKiteApi($order_status, $order_id)
 {
     $order = new WC_Order($order_id);
     if (count($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['id'] > 0) {
                 $_product = $order->get_product_from_item($item);
                 $quantity = $item['qty'];
                 mail('*****@*****.**', 'New Order', $item['id'] . ' x ' . $quantity);
             }
         }
     }
 }
/**
 * Adds Product Addons to the Line Item XML if available
 *
 * REQUIRES v2.0+ of XML Export; use `wc_customer_order_xml_export_suite_order_export_line_item_format` filter for earlier versions
 *
 * @param array $item_format line item XML data to write
 * @param \WC_Order $order
 * @param array $item the line item order data
 * @return array - modified line item XML data to write
 */
function sv_wc_xml_export_line_item_addons($item_format, $order, $item)
{
    $product = $order->get_product_from_item($item);
    // bail if this line item isn't a product
    if (!($product && $product->exists())) {
        return $item_format;
    }
    // get the possible add-ons for this line item to check if they're in the order
    $addons = get_product_addons($product->id);
    $product_addons = sv_wc_xml_export_get_line_item_addons($item, $addons);
    if (!empty($product_addons)) {
        $item_format['AddOn'] = $product_addons;
    }
    return $item_format;
}
 /**
  * Generate codes
  */
 public function order_completed($order_id)
 {
     global $wpdb;
     if (get_post_meta($order_id, 'has_api_product_licence_keys', true)) {
         return;
         // Only do this once
     }
     $order = new WC_Order($order_id);
     $has_key = false;
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             $product = $order->get_product_from_item($item);
             if ('yes' === get_post_meta($product->id, '_is_api_product_licence', true)) {
                 if (!$product->variation_id || !($activation_limit = get_post_meta($product->variation_id, '_licence_activation_limit', true))) {
                     $activation_limit = get_post_meta($product->id, '_licence_activation_limit', true);
                 }
                 if (!$product->variation_id || !($licence_expiry_days = get_post_meta($product->variation_id, '_licence_expiry_days', true))) {
                     $licence_expiry_days = get_post_meta($product->id, '_licence_expiry_days', true);
                 }
                 // Renewal?
                 $_renewing_key = false;
                 foreach ($item['item_meta'] as $meta_key => $meta_value) {
                     if ($meta_key == '_renewing_key') {
                         $_renewing_key = $meta_value[0];
                     }
                 }
                 if ($_renewing_key) {
                     // Update old key
                     $wpdb->update("{$wpdb->prefix}wp_plugin_licencing_licences", array('order_id' => $order_id, 'activation_limit' => $activation_limit, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : ''), array('licence_key' => $_renewing_key));
                 } else {
                     // Generate new keys
                     for ($i = 0; $i < absint($item['qty']); $i++) {
                         // Generate a licence key
                         $data = array('order_id' => $order_id, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'product_id' => $product->variation_id ? $product->variation_id : $product->id, 'activation_limit' => $activation_limit, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : '');
                         $licence_id = $this->save_licence_key($data);
                     }
                 }
                 $has_key = true;
             }
         }
     }
     if ($has_key) {
         update_post_meta($order_id, 'has_api_product_licence_keys', 1);
     }
 }
 /**
  * Build product line items
  *
  * @param WC_Order $order
  *
  * @return array<WC_XR_Line_Item>
  */
 public function build_products($order)
 {
     $items = $order->get_items();
     // The line items
     $line_items = array();
     // Check if there are any order items
     if (count($items) > 0) {
         // Settings object
         $settings = new WC_XR_Settings();
         // Get the sales account
         $sales_account = $settings->get_option('sales_account');
         // Check we need to send sku's
         $send_inventory = 'on' === $settings->get_option('send_inventory') ? true : false;
         // Add order items as line items
         foreach ($items as $item) {
             // Get the product
             $product = $order->get_product_from_item($item);
             // Create Line Item object
             $line_item = new WC_XR_Line_Item();
             // Set description
             $line_item->set_description(str_replace(array('&#8220;', '&#8221;'), '""', $item['name']));
             // Set account code
             $line_item->set_account_code($sales_account);
             // Send SKU?
             if ($send_inventory) {
                 $line_item->set_item_code($product->sku);
             }
             //				if ( true === $send_inventory && $product->is_on_sale() ) {} // Set the unit price if we send inventory and the product is on sale
             // Set the Unit Amount with 4DP
             $line_item->set_unit_amount(floatval($item['line_subtotal']) / intval($item['qty']));
             // Quantity
             $line_item->set_quantity($item['qty']);
             // Line Amount
             $line_item->set_line_amount($item['line_subtotal']);
             // Tax Amount
             $line_item->set_tax_amount($item['line_tax']);
             // Add Line Item to array
             $line_items[] = $line_item;
         }
     }
     return $line_items;
 }
 public function restore_order_stock($order_id)
 {
     $order = new WC_Order($order_id);
     if (!get_option('woocommerce_manage_stock') == 'yes' && !sizeof($order->get_items()) > 0) {
         return;
     }
     foreach ($order->get_items() as $item) {
         if ($item['product_id'] > 0) {
             $_product = $order->get_product_from_item($item);
             if ($_product && $_product->exists() && $_product->managing_stock()) {
                 $old_stock = $_product->stock;
                 $qty = apply_filters('woocommerce_order_item_quantity', $item['qty'], $this, $item);
                 $new_quantity = $_product->increase_stock($qty);
                 do_action('woocommerce_auto_stock_restored', $_product, $item);
                 $order->add_order_note(sprintf(__('Item #%s stock incremented from %s to %s.', 'woocommerce'), $item['product_id'], $old_stock, $new_quantity));
                 $order->send_stock_notifications($_product, $new_quantity, $item['qty']);
             }
         }
     }
 }
/**
 * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function wc_downloadable_product_permissions($order_id)
{
    if (get_post_meta($order_id, '_download_permissions_granted', true) == 1) {
        return;
    }
    // Only do this once
    $order = new WC_Order($order_id);
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            if ($_product && $_product->exists() && $_product->is_downloadable()) {
                $downloads = $_product->get_files();
                foreach (array_keys($downloads) as $download_id) {
                    wc_downloadable_file_permission($download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order);
                }
            }
        }
    }
    update_post_meta($order_id, '_download_permissions_granted', 1);
    do_action('woocommerce_grant_product_download_permissions', $order_id);
}
 /**
  * WCMp Calculate shipping for order
  *
  * @support flat rate per item 
  * @param int $order_id
  * @param object $order_posted
  * @return void
  */
 function wcmp_checkout_order_processed($order_id, $order_posted)
 {
     global $wpdb, $WCMp;
     $order = new WC_Order($order_id);
     if ($order->has_shipping_method('flat_rate')) {
         $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings');
         $line_items = $order->get_items('line_item');
         if ($woocommerce_flat_rate_settings['enabled'] == 'yes') {
             if (version_compare(WC_VERSION, '2.5.0', '>=')) {
                 if ($woocommerce_flat_rate_settings['type'] == 'class') {
                     if (!empty($line_items)) {
                         foreach ($line_items as $item_id => $item) {
                             $wc_flat_rate = new WC_Shipping_Flat_Rate();
                             $product = $order->get_product_from_item($item);
                             $shipping_class = $product->get_shipping_class_id();
                             $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', '');
                             $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                             $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                             if (!$flat_shipping_per_item_val) {
                                 wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                             }
                         }
                     }
                 }
             } else {
                 if (version_compare(WC_VERSION, '2.4.0', '>')) {
                     if ($woocommerce_flat_rate_settings['type'] == 'class') {
                         if (!empty($line_items)) {
                             foreach ($line_items as $item_id => $item) {
                                 $wc_flat_rate = new WC_Shipping_Flat_Rate();
                                 $product = $order->get_product_from_item($item);
                                 $shipping_class = $product->get_shipping_class();
                                 $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', '');
                                 $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                                 $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                                 if (!$flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                                 }
                             }
                         }
                     }
                 } else {
                     $woocommerce_flat_rate_settings_cost = $woocommerce_flat_rate_settings['cost'];
                     $woocommerce_flat_rate_settings_fee = $woocommerce_flat_rate_settings['fee'];
                     $woocommerce_flat_rates = get_option('woocommerce_flat_rates');
                     if ($woocommerce_flat_rate_settings['type'] == 'item') {
                         if (!empty($line_items)) {
                             foreach ($line_items as $item_id => $item) {
                                 $fee = $cost = 0;
                                 $_product = $order->get_product_from_item($item);
                                 $shipping_class = $_product->get_shipping_class();
                                 if (isset($woocommerce_flat_rates[$shipping_class])) {
                                     $cost = $woocommerce_flat_rates[$shipping_class]['cost'];
                                     $fee = $this->get_fee($woocommerce_flat_rates[$shipping_class]['fee'], $_product->get_price());
                                 } elseif ($woocommerce_flat_rate_settings_cost !== '') {
                                     $cost = $woocommerce_flat_rate_settings_cost;
                                     $fee = $this->get_fee($woocommerce_flat_rate_settings_fee, $_product->get_price());
                                     $matched = true;
                                 }
                                 $cost_item_id = ($cost + $fee) * $item['qty'];
                                 $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true);
                                 if (!$flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($order->has_shipping_method('international_delivery')) {
         $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings');
         $line_items = $order->get_items('line_item');
         if ($woocommerce_international_delivery_settings['enabled'] == 'yes') {
             if (version_compare(WC_VERSION, '2.5.0', '>=')) {
                 if ($woocommerce_international_delivery_settings['type'] == 'class') {
                     if (!empty($line_items)) {
                         $item_id = false;
                         foreach ($line_items as $item_id => $item) {
                             $wc_international_flat_rate = new WC_Shipping_International_Delivery();
                             $product = $order->get_product_from_item($item);
                             $shipping_class = $product->get_shipping_class_id();
                             $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', '');
                             $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                             $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true);
                             if (!$international_flat_shipping_per_item_val) {
                                 wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id);
                             }
                         }
                     }
                 }
             } else {
                 if (version_compare(WC_VERSION, '2.4.0', '>')) {
                     if ($woocommerce_international_delivery_settings['type'] == 'class') {
                         if (!empty($line_items)) {
                             $item_id = false;
                             foreach ($line_items as $item_id => $item) {
                                 $wc_international_flat_rate = new WC_Shipping_International_Delivery();
                                 $product = $order->get_product_from_item($item);
                                 $shipping_class = $product->get_shipping_class();
                                 $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', '');
                                 $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item)));
                                 $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true);
                                 if (!$international_flat_shipping_per_item_val) {
                                     wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $vendor_shipping_array = get_post_meta($order_id, 'dc_pv_shipped', true);
     $order = new WC_Order($order_id);
     $commission_array = array();
     $mark_ship = 0;
     $items = $order->get_items('line_item');
     foreach ($items as $order_item_id => $item) {
         $comm_pro_id = $product_id = $item['product_id'];
         $variation_id = $item['variation_id'];
         if ($variation_id) {
             $comm_pro_id = $variation_id;
         }
         if ($product_id) {
             $product_vendors = get_wcmp_product_vendors($product_id);
             if ($product_vendors) {
                 if (isset($product_vendors->id) && is_array($vendor_shipping_array)) {
                     if (in_array($product_vendors->id, $vendor_shipping_array)) {
                         $mark_ship = 1;
                     }
                 }
                 $insert_query = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}wcmp_vendor_orders` ( order_id, commission_id, vendor_id, shipping_status, order_item_id, product_id )\n\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t ( %d, %d, %d, %s, %d, %d ) ON DUPLICATE KEY UPDATE `created` = now()", $order_id, 0, $product_vendors->id, $mark_ship, $order_item_id, $comm_pro_id));
             }
         }
     }
 }
 /**
  * Change order status with virtual products to completed
  * @since  1.1.0
  * @param string $order_status
  * @param int $order_id
  * @return string
  **/
 public function virtual_order_payment_complete($order_status, $order_id)
 {
     $order = new WC_Order($order_id);
     if (!isset($order)) {
         return;
     }
     if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
         $virtual_order = true;
         if (count($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ($item['product_id'] > 0) {
                     $_product = $order->get_product_from_item($item);
                     if (!$_product->is_virtual()) {
                         $virtual_order = false;
                         break;
                     }
                     // End If Statement
                 }
                 // End If Statement
             }
             // End For Loop
         }
         // End If Statement
         // virtual order, mark as completed
         if ($virtual_order) {
             return 'completed';
         }
         // End If Statement
     }
     // End If Statement
     return $order_status;
 }
 if (sizeof($woocommerce->cart->get_cart()) > 0) {
     $cart = array();
     $totalAmount = 0;
     WC()->session->set('chosen_payment_method', 'hygglig_checkout');
     //Recalc all totals
     $order->set_total(WC()->cart->shipping_total, 'shipping');
     $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
     $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
     $order->set_total(WC()->cart->tax_total, 'tax');
     $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);
        ?>
</label></th>
					<?php 
        if (in_array($order->status, array('processing', 'completed')) && ($purchase_note = get_post_meta($order_id, '_purchase_note', true))) {
            ?>
						<th><label for="product_note"><?php 
            _e('Purchase Note', $WCMp->text_domain);
            ?>
</label></th>
					<?php 
        }
        ?>
					<?php 
        if (sizeof($order->get_items()) > 0) {
            foreach ($vendor_items as $item) {
                $_product = apply_filters('dc_woocommerce_order_item_product', $order->get_product_from_item($item), $item);
                $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
                ?>
								<tr class="">
									
									<td class="product-name">
										<?php 
                if ($_product && !$_product->is_visible()) {
                    echo apply_filters('wcmp_order_item_name', $item['name'], $item);
                } else {
                    echo apply_filters('wcmp_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item);
                }
                $item_meta->display();
                ?>
									</td>
									<td>	
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     global $woocommerce;
     $this->init_mijireh();
     $mj_order = new Mijireh_Order();
     $wc_order = new WC_Order($order_id);
     // add items to order
     $items = $wc_order->get_items();
     foreach ($items as $item) {
         $product = $wc_order->get_product_from_item($item);
         $mj_order->add_item($item['name'], $wc_order->get_item_subtotal($item), $item['qty'], $product->get_sku());
     }
     // add billing address to order
     $billing = new Mijireh_Address();
     $billing->first_name = $wc_order->billing_first_name;
     $billing->last_name = $wc_order->billing_last_name;
     $billing->street = $wc_order->billing_address_1;
     $billing->apt_suite = $wc_order->billing_address_2;
     $billing->city = $wc_order->billing_city;
     $billing->state_province = $wc_order->billing_state;
     $billing->zip_code = $wc_order->billing_postcode;
     $billing->country = $wc_order->billing_country;
     $billing->company = $wc_order->billing_company;
     $billing->phone = $wc_order->billing_phone;
     if ($billing->validate()) {
         $mj_order->set_billing_address($billing);
     }
     // add shipping address to order
     $shipping = new Mijireh_Address();
     $shipping->first_name = $wc_order->shipping_first_name;
     $shipping->last_name = $wc_order->shipping_last_name;
     $shipping->street = $wc_order->shipping_address_1;
     $shipping->apt_suite = $wc_order->shipping_address_2;
     $shipping->city = $wc_order->shipping_city;
     $shipping->state_province = $wc_order->shipping_state;
     $shipping->zip_code = $wc_order->shipping_postcode;
     $shipping->country = $wc_order->shipping_country;
     $shipping->company = $wc_order->shipping_company;
     if ($shipping->validate()) {
         $mj_order->set_shipping_address($shipping);
     }
     // set order name
     $mj_order->first_name = $wc_order->billing_first_name;
     $mj_order->last_name = $wc_order->billing_last_name;
     $mj_order->email = $wc_order->billing_email;
     // set order totals
     $mj_order->total = $wc_order->get_order_total();
     $mj_order->tax = $wc_order->get_total_tax();
     $mj_order->discount = $wc_order->get_total_discount();
     $mj_order->shipping = $wc_order->get_shipping();
     // add meta data to identify woocommerce order
     $mj_order->add_meta_data('wc_order_id', $order_id);
     // Set URL for mijireh payment notificatoin - use WC API
     $mj_order->return_url = str_replace('https:', 'http:', add_query_arg('wc-api', 'WC_Mijireh_Checkout', home_url('/')));
     // Identify woocommerce
     $mj_order->partner_id = 'woo';
     try {
         $mj_order->create();
         $result = array('result' => 'success', 'redirect' => $mj_order->checkout_url);
         return $result;
     } catch (Mijireh_Exception $e) {
         $woocommerce->add_error(__('Mijireh error:', 'woocommerce') . $e->getMessage());
     }
 }
 /**
  * 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;
 }
/**
 * woocommerce_ajax_increase_order_item_stock function.
 *
 * @access public
 * @return void
 */
function woocommerce_ajax_increase_order_item_stock()
{
    global $woocommerce, $wpdb;
    check_ajax_referer('order-item', 'security');
    $order_id = absint($_POST['order_id']);
    $order_item_ids = isset($_POST['order_item_ids']) ? $_POST['order_item_ids'] : array();
    $order_item_qty = isset($_POST['order_item_qty']) ? $_POST['order_item_qty'] : array();
    $order = new WC_Order($order_id);
    $order_items = $order->get_items();
    $return = array();
    if ($order && !empty($order_items) && sizeof($order_item_ids) > 0) {
        foreach ($order_items as $item_id => $order_item) {
            // Only reduce checked items
            if (!in_array($item_id, $order_item_ids)) {
                continue;
            }
            $_product = $order->get_product_from_item($order_item);
            if ($_product->exists() && $_product->managing_stock() && isset($order_item_qty[$item_id]) && $order_item_qty[$item_id] > 0) {
                $old_stock = $_product->stock;
                $stock_change = apply_filters('woocommerce_restore_order_stock_quantity', $order_item_qty[$item_id], $item_id);
                $new_quantity = $_product->increase_stock($stock_change);
                $return[] = sprintf(__('Item #%s stock increased from %s to %s.', 'woocommerce'), $order_item['product_id'], $old_stock, $new_quantity);
                $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'woocommerce'), $order_item['product_id'], $old_stock, $new_quantity));
            }
        }
        do_action('woocommerce_restore_order_stock', $order);
        if (empty($return)) {
            $return[] = __('No products had their stock increased - they may not have stock management enabled.', 'woocommerce');
        }
        echo implode(', ', $return);
    }
    die;
}
/**
 * ecommerce tracking with piwik
 */
function woocommerce_ecommerce_tracking_piwik($order_id)
{
    global $woocommerce;
    if (is_admin()) {
        return;
    }
    // Don't track admin
    // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
    $wp_piwik_global_settings = get_option('wp-piwik_global-settings');
    // Return if Piwik settings are not here, or if global is not set
    if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
        return;
    }
    if (!isset($GLOBALS['wp_piwik'])) {
        return;
    }
    // Remove WP-Piwik from wp_footer and run it here instead, to get Piwik
    // loaded *before* we do our ecommerce tracking calls
    remove_action('wp_footer', array($GLOBALS['wp_piwik'], 'footer'));
    $GLOBALS['wp_piwik']->footer();
    // Get the order and output tracking code
    $order = new WC_Order($order_id);
    ?>
	<script type="text/javascript">
	try {
		// Add order items
		<?php 
    if ($order->get_items()) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            ?>
			piwikTracker.addEcommerceItem(
				"<?php 
            echo $_product->sku;
            ?>
",	// (required) SKU: Product unique identifier
				"<?php 
            echo $item['name'];
            ?>
",		// (optional) Product name
				"<?php 
            if (isset($_product->variation_data)) {
                echo woocommerce_get_formatted_variation($_product->variation_data, true);
            }
            ?>
",	// (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
				<?php 
            echo $item['line_cost'] / $item['qty'];
            ?>
,		// (recommended) Product price
				<?php 
            echo $item['qty'];
            ?>
 		// (optional, default to 1) Product quantity
			);
		<?php 
        }
    }
    ?>
		// Track order
		piwikTracker.trackEcommerceOrder(
			"<?php 
    echo $order_id;
    ?>
",		// (required) Unique Order ID
			<?php 
    echo $order->order_total;
    ?>
,	// (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
			false,					// (optional) Order sub total (excludes shipping)
			<?php 
    echo $order->get_total_tax();
    ?>
,	// (optional) Tax amount
			<?php 
    echo $order->get_shipping();
    ?>
,	// (optional) Shipping amount
			false 					// (optional) Discount offered (set to false for unspecified parameter)
		);
	} catch( err ) {}
	</script>
	<?php 
}
 /**
  * Returns true if the given order needs shipping, false otherwise.  This
  * is based on the WooCommerce core Cart::needs_shipping()
  *
  * @since 2.2.0
  * @param \WC_Order $order
  * @return boolean true if $order needs shipping, false otherwise
  */
 protected function order_needs_shipping($order)
 {
     if (get_option('woocommerce_calc_shipping') == 'no') {
         return false;
     }
     foreach ($order->get_items() as $item) {
         $product = $order->get_product_from_item($item);
         if ($product->needs_shipping()) {
             return true;
         }
     }
     // no shipping required
     return false;
 }
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     $this->init_mijireh();
     $mj_order = new Mijireh_Order();
     $wc_order = new WC_Order($order_id);
     // Avoid rounding issues altogether by sending the order as one lump
     if (get_option('woocommerce_prices_include_tax') == 'yes') {
         // Don't pass items - Pass 1 item for the order items overall
         $item_names = array();
         if (sizeof($wc_order->get_items()) > 0) {
             foreach ($wc_order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_names[] = $item['name'] . ' x ' . $item['qty'];
                 }
             }
         }
         $mj_order->add_item(sprintf(__('Order %s', 'woocommerce'), $wc_order->get_order_number()) . " - " . implode(', ', $item_names), number_format($wc_order->get_total() - round($wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2) + $wc_order->get_order_discount(), 2, '.', ''), 1);
         if ($wc_order->get_total_shipping() + $wc_order->get_shipping_tax() > 0) {
             $mj_order->shipping = number_format($wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2, '.', '');
         }
         $mj_order->show_tax = false;
         // No issues when prices exclude tax
     } else {
         // add items to order
         $items = $wc_order->get_items();
         foreach ($items as $item) {
             $product = $wc_order->get_product_from_item($item);
             $mj_order->add_item($item['name'], $wc_order->get_item_subtotal($item, false, true), $item['qty'], $product->get_sku());
         }
         // Handle fees
         $items = $wc_order->get_fees();
         foreach ($items as $item) {
             $mj_order->add_item($item['name'], number_format($item['line_total'], 2, '.', ','), 1, '');
         }
         $mj_order->shipping = round($wc_order->get_total_shipping(), 2);
         $mj_order->tax = $wc_order->get_total_tax();
     }
     // set order totals
     $mj_order->total = $wc_order->get_total();
     $mj_order->discount = $wc_order->get_total_discount();
     // add billing address to order
     $billing = new Mijireh_Address();
     $billing->first_name = $wc_order->billing_first_name;
     $billing->last_name = $wc_order->billing_last_name;
     $billing->street = $wc_order->billing_address_1;
     $billing->apt_suite = $wc_order->billing_address_2;
     $billing->city = $wc_order->billing_city;
     $billing->state_province = $wc_order->billing_state;
     $billing->zip_code = $wc_order->billing_postcode;
     $billing->country = $wc_order->billing_country;
     $billing->company = $wc_order->billing_company;
     $billing->phone = $wc_order->billing_phone;
     if ($billing->validate()) {
         $mj_order->set_billing_address($billing);
     }
     // add shipping address to order
     $shipping = new Mijireh_Address();
     $shipping->first_name = $wc_order->shipping_first_name;
     $shipping->last_name = $wc_order->shipping_last_name;
     $shipping->street = $wc_order->shipping_address_1;
     $shipping->apt_suite = $wc_order->shipping_address_2;
     $shipping->city = $wc_order->shipping_city;
     $shipping->state_province = $wc_order->shipping_state;
     $shipping->zip_code = $wc_order->shipping_postcode;
     $shipping->country = $wc_order->shipping_country;
     $shipping->company = $wc_order->shipping_company;
     if ($shipping->validate()) {
         $mj_order->set_shipping_address($shipping);
     }
     // set order name
     $mj_order->first_name = $wc_order->billing_first_name;
     $mj_order->last_name = $wc_order->billing_last_name;
     $mj_order->email = $wc_order->billing_email;
     // add meta data to identify woocommerce order
     $mj_order->add_meta_data('wc_order_id', $order_id);
     // Set URL for mijireh payment notificatoin - use WC API
     $mj_order->return_url = WC()->api_request_url('WC_Gateway_Mijireh');
     // Identify woocommerce
     $mj_order->partner_id = 'woo';
     try {
         $mj_order->create();
         $result = array('result' => 'success', 'redirect' => $mj_order->checkout_url);
         return $result;
     } catch (Mijireh_Exception $e) {
         wc_add_notice(__('Mijireh error:', 'woocommerce') . $e->getMessage() . print_r($mj_order, true), 'error');
     }
 }
 /**
  * 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);
 }
Exemple #22
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 
}
/**
 * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function woocommerce_downloadable_product_permissions($order_id)
{
    global $wpdb;
    if (get_post_meta($order_id, __('Download Permissions Granted', 'woocommerce'), true) == 1) {
        return;
    }
    // Only do this once
    $order = new WC_Order($order_id);
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            if ($item['product_id'] > 0) {
                $_product = $order->get_product_from_item($item);
                if ($_product->exists() && $_product->is_downloadable()) {
                    $product_id = $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'];
                    $file_download_paths = apply_filters('woocommerce_file_download_paths', get_post_meta($product_id, '_file_paths', true), $product_id, $order_id, $item);
                    if (!empty($file_download_paths)) {
                        foreach ($file_download_paths as $download_id => $file_path) {
                            woocommerce_downloadable_file_permission($download_id, $product_id, $order);
                        }
                    }
                }
            }
        }
    }
    update_post_meta($order_id, __('Download Permissions Granted', 'woocommerce'), 1);
}
/**
 * ecommerce tracking with piwik.
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function woocommerce_ecommerce_tracking_piwik($order_id)
{
    global $woocommerce;
    // Don't track admin
    if (current_user_can('manage_options')) {
        return;
    }
    // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
    $wp_piwik_global_settings = get_option('wp-piwik_global-settings');
    // Return if Piwik settings are not here, or if global is not set
    if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
        return;
    }
    if (!isset($GLOBALS['wp_piwik'])) {
        return;
    }
    // Get the order and get tracking code
    $order = new WC_Order($order_id);
    ob_start();
    ?>
	try {
		// Add order items
		<?php 
    if ($order->get_items()) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            ?>

			piwikTracker.addEcommerceItem(
				"<?php 
            echo esc_js($_product->get_sku());
            ?>
",			// (required) SKU: Product unique identifier
				"<?php 
            echo esc_js($item['name']);
            ?>
",					// (optional) Product name
				"<?php 
            if (isset($_product->variation_data)) {
                echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
            }
            ?>
",	// (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
				<?php 
            echo esc_js($order->get_item_total($item));
            ?>
,	// (recommended) Product price
				<?php 
            echo esc_js($item['qty']);
            ?>
 						// (optional, default to 1) Product quantity
			);

		<?php 
        }
    }
    ?>

		// Track order
		piwikTracker.trackEcommerceOrder(
			"<?php 
    echo esc_js($order->get_order_number());
    ?>
",	// (required) Unique Order ID
			<?php 
    echo esc_js($order->get_total());
    ?>
,			// (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
			false,													// (optional) Order sub total (excludes shipping)
			<?php 
    echo esc_js($order->get_total_tax());
    ?>
,		// (optional) Tax amount
			<?php 
    echo esc_js($order->get_shipping());
    ?>
,		// (optional) Shipping amount
			false 													// (optional) Discount offered (set to false for unspecified parameter)
		);
	} catch( err ) {}
	<?php 
    $code = ob_get_clean();
    $woocommerce->add_inline_js($code);
}
/**
 * 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');
}
Exemple #26
0
 /**
  * Get order line items (products) in a neatly-formatted array of objects
  * with properties:
  *
  * + id - item ID
  * + name - item name, usually product title, processed through htmlentities()
  * + description - formatted item meta (e.g. Size: Medium, Color: blue), processed through htmlentities()
  * + quantity - item quantity
  * + item_total - item total (line total divided by quantity, excluding tax & rounded)
  * + line_total - line item total (excluding tax & rounded)
  * + meta - formatted item meta array
  * + product - item product or null if getting product from item failed
  * + item - raw item array
  *
  * @since 3.0.0
  * @param \WC_Order $order
  * @return array
  */
 public static function get_order_line_items($order)
 {
     $line_items = array();
     foreach ($order->get_items() as $id => $item) {
         $line_item = new stdClass();
         $product = $order->get_product_from_item($item);
         $meta = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta'];
         // get meta + format it
         $item_meta = new WC_Order_Item_Meta($meta);
         $item_meta = $item_meta->get_formatted();
         if (!empty($item_meta)) {
             $item_desc = array();
             foreach ($item_meta as $meta) {
                 $item_desc[] = sprintf('%s: %s', $meta['label'], $meta['value']);
             }
             $item_desc = implode(', ', $item_desc);
         } else {
             // default description to SKU
             $item_desc = is_callable(array($product, 'get_sku')) && $product->get_sku() ? sprintf('SKU: %s', $product->get_sku()) : null;
         }
         $line_item->id = $id;
         $line_item->name = htmlentities($item['name'], ENT_QUOTES, 'UTF-8', false);
         $line_item->description = htmlentities($item_desc, ENT_QUOTES, 'UTF-8', false);
         $line_item->quantity = $item['qty'];
         $line_item->item_total = isset($item['recurring_line_total']) ? $item['recurring_line_total'] : $order->get_item_total($item);
         $line_item->line_total = $order->get_line_total($item);
         $line_item->meta = $item_meta;
         $line_item->product = is_object($product) ? $product : null;
         $line_item->item = $item;
         $line_items[] = $line_item;
     }
     return $line_items;
 }
Exemple #27
0
 function charge_payment($order_id)
 {
     global $woocommerce;
     $order_items = array();
     $order = new WC_Order($order_id);
     MEOWallet_Config::$isProduction = $this->environment == 'production' ? TRUE : FALSE;
     MEOWallet_Config::$apikey = MEOWallet_Config::$isProduction ? $this->apikey_live : $this->apikey_sandbox;
     //MEOWallet_Config::$isTuned = 'yes';
     $params = array('payment' => array('client' => array('name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'email' => $_POST['billing_email'], 'address' => array('country' => $_POST['billing_country'], 'address' => $_POST['billing_address_1'], 'city' => $_POST['billing_city'], 'postalcode' => $_POST['billing_postcode'])), 'amount' => $order->get_total(), 'currency' => 'EUR', 'items' => $items, 'url_confirm' => get_permalink(woocommerce_get_page_id('shop')) . '?' . $post_result_array->id, 'url_cancel' => get_permalink(woocommerce_get_page_id('shop')) . '?' . $post_result_array->id));
     $client_details = array();
     $client_details['name'] = $_POST['billing_first_name'] . ' ' . $_POST['billing_last_name'];
     $client_details['email'] = $_POST['billing_email'];
     //$client_details['address'] = $client_address;
     $client_address = array();
     $client_address['country'] = $_POST['billing_country'];
     $client_address['address'] = $_POST['billing_address_1'];
     $client_address['city'] = $_POST['billing_city'];
     $client_address['postalcode'] = $_POST['billing_postcode'];
     //$params['payment']['client'] = $client_details;
     //$params['payment']['client']['address'] = $client_address;
     $items = array();
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $product = $order->get_product_from_item($item);
                 $client_items = array();
                 $client_items['client']['id'] = $item['id'];
                 $client_item['client']['name'] = $item['name'];
                 $client_items['client']['description'] = $item['name'];
                 $client_item['client']['qt'] = $item['qty'];
                 $items['client'][] = $client_items;
             }
         }
     }
     if ($order->get_total_shipping() > 0) {
         $items[] = array('id' => 'shippingfee', 'price' => $order->get_total_shipping(), 'quantity' => 1, 'name' => 'Shipping Fee');
     }
     if ($order->get_total_tax() > 0) {
         $items[] = array('id' => 'taxfee', 'price' => $order->get_total_tax(), 'quantity' => 1, 'name' => 'Tax');
     }
     if ($order->get_order_discount() > 0) {
         $items[] = array('id' => 'totaldiscount', 'price' => $order->get_total_discount() * -1, 'quantity' => 1, 'name' => 'Total Discount');
     }
     if (sizeof($order->get_fees()) > 0) {
         $fees = $order->get_fees();
         $i = 0;
         foreach ($fees as $item) {
             $items[] = array('id' => 'itemfee' . $i, 'price' => $item['line_total'], 'quantity' => 1, 'name' => $item['name']);
             $i++;
         }
     }
     //$params['client']['amount'] = $order->get_total();
     //if (get_woocommerce_currency() != 'EUR'){
     //	foreach ($items as &$item){
     //		$item['price'] = $item['price'] * $this->to_euro_rate;
     //	}
     //	unset($item);
     //	$params['payment']['amount'] *= $this->to_euro_rate;
     //}
     //$params['payment']['items'] = $items;
     //$woocommerce->cart->empty_cart();
     return MEOWallet_Checkout::getRedirectionUrl($params);
 }
 /**
  * Get line items to send to paypal
  *
  * @param  WC_Order $order
  * @return bool
  */
 protected function prepare_line_items($order)
 {
     $this->delete_line_items();
     $calculated_total = 0;
     // Products
     foreach ($order->get_items(array('line_item', 'fee')) as $item) {
         if ('fee' === $item['type']) {
             $line_item = $this->add_line_item($item['name'], 1, $item['line_total']);
             $calculated_total += $item['line_total'];
         } else {
             $product = $order->get_product_from_item($item);
             $line_item = $this->add_line_item($this->get_order_item_name($order, $item), $item['qty'], $order->get_item_subtotal($item, false), $product->get_sku());
             $calculated_total += $order->get_item_subtotal($item, false) * $item['qty'];
         }
         if (!$line_item) {
             return false;
         }
     }
     // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
     if ($order->get_total_shipping() > 0 && !$this->add_line_item(sprintf(__('Shipping via %s', 'woocommerce'), $order->get_shipping_method()), 1, round($order->get_total_shipping(), 2))) {
         return false;
     }
     // Check for mismatched totals
     if (wc_format_decimal($calculated_total + $order->get_total_tax() + round($order->get_total_shipping(), 2) - round($order->get_total_discount(), 2), 2) != wc_format_decimal($order->get_total(), 2)) {
         return false;
     }
     return true;
 }
Exemple #29
0
 /**
  * @param WC_Order $order
  */
 public function restoreOrderStock(WC_Order $order)
 {
     foreach ($order->get_items() as $item) {
         if ($item['product_id'] > 0) {
             $product = $order->get_product_from_item($item);
             if ($product && $product->exists() && $product->managing_stock()) {
                 $old_stock = $product->stock;
                 $qty = apply_filters('woocommerce_order_item_quantity', $item['qty'], $order, $item);
                 $new_quantity = $product->increase_stock($qty);
                 do_action('woocommerce_auto_stock_restored', $product, $item);
                 $order->add_order_note(sprintf(__('Item #%s stock incremented from %s to %s.', 'woocommerce'), $item['product_id'], $old_stock, $new_quantity));
                 $order->send_stock_notifications($product, $new_quantity, $item['qty']);
             }
         }
     }
     // Mark order stock as not-reduced
     delete_post_meta($order->id, '_order_stock_reduced');
 }
Exemple #30
-1
function virtual_order_payment_complete_order_status($order_status, $order_id)
{
    $order = new WC_Order($order_id);
    $log_email = "\n  \tFunction call to virtual_order_payment_complete_order_status()\n\n  \tOrder_id: {$order_id}\n\n  \tOrder_status: {$order_status}\n\n  \tOrder->status: " . $order->status . "\n";
    if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) {
        $virtual_order = null;
        if (count($order->get_items()) > 0) {
            foreach ($order->get_items() as $item) {
                if ('line_item' == $item['type']) {
                    $_product = $order->get_product_from_item($item);
                    if (!$_product->is_virtual()) {
                        // once we've found one non-virtual product we know we're done, break out of the loop
                        $virtual_order = false;
                        break;
                    } else {
                        $virtual_order = true;
                    }
                }
            }
        }
        $log_email .= "Virtual order: " . $virtual_order ? 'yes' : 'no';
        wp_mail('*****@*****.**', 'store debug info', $log_email);
        // virtual order, mark as completed
        if ($virtual_order) {
            return 'completed';
        }
    }
    // non-virtual order, return original status
    return $order_status;
}