Ejemplo n.º 1
0
 function sr_items_to_values($all_order_items = array())
 {
     global $wpdb;
     if (count($all_order_items) <= 0 || !defined('SR_IS_WOO16') || !defined('SR_IS_WOO22')) {
         return $all_order_items;
     }
     $values = array();
     $attributes_name_to_slug = sr_get_attributes_name_to_slug();
     $prefix = defined('SR_IS_WOO16') && SR_IS_WOO16 == "true" ? '' : '_';
     if (!empty($all_order_items['order_date'])) {
         $order_date = $all_order_items['order_date'];
     }
     if (!empty($all_order_items['order_status'])) {
         $order_status = $all_order_items['order_status'];
     }
     unset($all_order_items['order_date']);
     unset($all_order_items['order_status']);
     foreach ($all_order_items as $order_id => $order_items) {
         foreach ($order_items as $item) {
             $order_item = array();
             $order_item['order_id'] = $order_id;
             if (!function_exists('get_product')) {
                 $product_id = !empty($prefix) && !empty($item[$prefix . 'id']) ? $item[$prefix . 'id'] : $item['id'];
             } else {
                 $product_id = !empty($item['product_id']) ? $item['product_id'] : '';
                 $product_id = !empty($prefix) && !empty($item[$prefix . 'product_id']) ? $item[$prefix . 'product_id'] : $product_id;
             }
             // end if
             $order_item['product_name'] = get_the_title($product_id);
             $variation_id = !empty($item['variation_id']) ? $item['variation_id'] : '';
             $variation_id = !empty($prefix) && !empty($item[$prefix . 'variation_id']) ? $item[$prefix . 'variation_id'] : $variation_id;
             $order_item['product_id'] = $variation_id > 0 ? $variation_id : $product_id;
             if ($variation_id > 0) {
                 $variation_name = array();
                 if (!function_exists('get_product') && count($item['item_meta']) > 0) {
                     foreach ($item['item_meta'] as $items) {
                         $variation_name['attribute_' . $items['meta_name']] = $items['meta_value'];
                     }
                 } else {
                     $att_name_to_slug_prod = !empty($attributes_name_to_slug[$product_id]) ? $attributes_name_to_slug[$product_id] : array();
                     foreach ($item as $item_meta_key => $item_meta_value) {
                         if (array_key_exists($item_meta_key, $att_name_to_slug_prod)) {
                             $variation_name['attribute_' . $item_meta_key] = is_array($item_meta_value) && !empty($item_meta_value[0]) ? $item_meta_value[0] : $item_meta_value;
                         } elseif (in_array($item_meta_key, $att_name_to_slug_prod)) {
                             $variation_name['attribute_' . $item_meta_key] = is_array($item_meta_value) && !empty($item_meta_value[0]) ? $item_meta_value[0] : $item_meta_value;
                         }
                     }
                 }
                 $order_item['product_name'] .= ' (' . woocommerce_get_formatted_variation($variation_name, true) . ')';
             }
             $qty = !empty($item['qty']) ? $item['qty'] : '';
             $order_item['quantity'] = !empty($prefix) && !empty($item[$prefix . 'qty']) ? $item[$prefix . 'qty'] : $qty;
             $line_total = !empty($item['line_total']) ? $item['line_total'] : '';
             $line_total = !empty($prefix) && !empty($item[$prefix . 'line_total']) ? $item[$prefix . 'line_total'] : $line_total;
             $order_item['sales'] = $line_total;
             $line_subtotal = !empty($item['line_subtotal']) ? $item['line_subtotal'] : '';
             $line_subtotal = !empty($prefix) && !empty($item[$prefix . 'line_subtotal']) ? $item[$prefix . 'line_subtotal'] : $line_subtotal;
             $order_item['order_date'] = !empty($item['order_date']) ? $item['order_date'] : $order_date;
             $order_item['order_status'] = !empty($item['order_status']) ? $item['order_status'] : $order_status;
             $order_item['discount'] = $line_subtotal - $line_total;
             if (!empty($item['sku'])) {
                 $order_item['sku'] = $item['sku'];
             } else {
                 $prod_sku = get_post_meta($product_id, '_sku', true);
                 $order_item['sku'] = !empty($prod_sku) ? $prod_sku : '';
             }
             if (!empty($item['category'])) {
                 $order_item['category'] = $item['category'];
             } else {
                 $category = get_the_terms($product_id, 'product_cat');
                 $order_item['category'] = !empty($category) ? $category[0]->name : '';
             }
             if (empty($order_item['product_id']) || empty($order_item['order_id']) || empty($order_item['quantity'])) {
                 continue;
             }
             $values[] = "( {$order_item['product_id']}, {$order_item['order_id']},'{$order_item['order_date']}', '{$order_item['order_status']}', '{$order_item['product_name']}', '{$order_item['sku']}' , '{$order_item['category']}' , {$order_item['quantity']}, " . (empty($order_item['sales']) ? 0 : $order_item['sales']) . ", " . (empty($order_item['discount']) ? 0 : $order_item['discount']) . " )";
         }
     }
     return $values;
 }
Ejemplo n.º 2
0
 function sr_items_to_values($all_order_items = array())
 {
     global $wpdb;
     if (count($all_order_items) <= 0 || !defined('IS_WOO16')) {
         return $all_order_items;
     }
     $values = array();
     $attributes_name_to_slug = sr_get_attributes_name_to_slug();
     $prefix = defined('IS_WOO16') && IS_WOO16 ? '' : '_';
     foreach ($all_order_items as $order_id => $order_items) {
         foreach ($order_items as $item) {
             $order_item = array();
             $order_item['order_id'] = $order_id;
             if (!function_exists('get_product')) {
                 $product_id = !empty($prefix) && isset($item[$prefix . 'id']) ? $item[$prefix . 'id'] : $item['id'];
             } else {
                 $product_id = !empty($prefix) && isset($item[$prefix . 'product_id']) ? $item[$prefix . 'product_id'] : $item['product_id'];
             }
             // end if
             $order_item['product_name'] = get_the_title($product_id);
             $variation_id = !empty($prefix) && isset($item[$prefix . 'variation_id']) ? $item[$prefix . 'variation_id'] : $item['variation_id'];
             $order_item['product_id'] = $variation_id > 0 ? $variation_id : $product_id;
             if ($variation_id > 0) {
                 $variation_name = array();
                 if (!function_exists('get_product') && count($item['item_meta']) > 0) {
                     foreach ($item['item_meta'] as $items) {
                         $variation_name['attribute_' . $items['meta_name']] = $items['meta_value'];
                     }
                 } else {
                     foreach ($item as $item_meta_key => $item_meta_value) {
                         if (array_key_exists($item_meta_key, $attributes_name_to_slug[$product_id])) {
                             $variation_name['attribute_' . $item_meta_key] = is_array($item_meta_value) && isset($item_meta_value[0]) ? $item_meta_value[0] : $item_meta_value;
                         } elseif (in_array($item_meta_key, $attributes_name_to_slug[$product_id])) {
                             $variation_name['attribute_' . $item_meta_key] = is_array($item_meta_value) && isset($item_meta_value[0]) ? $item_meta_value[0] : $item_meta_value;
                         }
                     }
                 }
                 $order_item['product_name'] .= ' (' . woocommerce_get_formatted_variation($variation_name, true) . ')';
             }
             $order_item['quantity'] = !empty($prefix) && isset($item[$prefix . 'qty']) ? $item[$prefix . 'qty'] : $item['qty'];
             $line_total = !empty($prefix) && isset($item[$prefix . 'line_total']) ? $item[$prefix . 'line_total'] : $item['line_total'];
             $order_item['sales'] = $line_total;
             $line_subtotal = !empty($prefix) && isset($item[$prefix . 'line_subtotal']) ? $item[$prefix . 'line_subtotal'] : $item['line_subtotal'];
             $order_item['discount'] = $line_subtotal - $line_total;
             if (empty($order_item['product_id']) || empty($order_item['order_id']) || empty($order_item['quantity'])) {
                 continue;
             }
             $values[] = "( {$order_item['product_id']}, {$order_item['order_id']}, '{$order_item['product_name']}', {$order_item['quantity']}, " . (empty($order_item['sales']) ? 0 : $order_item['sales']) . ", " . (empty($order_item['discount']) ? 0 : $order_item['discount']) . " )";
         }
     }
     return $values;
 }