<?php
global $woocommerce, $nasa_opt, $product, $post, $wpdb;
date_default_timezone_set("Asia/Bangkok");
$date_from = date('Y-m-d h:i:s', strtotime('-30 days'));
$date_to = date('Y-m-d h:i:s');
$pro = array();
$u_orders = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ('wc-processing','wc-completed') AND post_date BETWEEN '{$date_from}' AND '{$date_to}' ");
if($u_orders && $u_orders != null && (is_object($u_orders) || is_array($u_orders))) {
foreach($u_orders as $u_order){
$order = null; $orderId = null;
$order = new WC_Order($u_order->ID);
if($order) {
foreach ($order->get_items() as $item_id => $item ) {
$itID = 0;
$itID = (int)$item['product_id'];
if($itID > 0) {
if($pro[$itID] == null || $pro[$itID] == 'undefined' || empty($pro[$itID]) || is_nan($pro[$itID]) || $pro[$itID] == '' || $pro[$itID] == 0) {
$pro[$itID] = (int) $item->get_quantity();
} else {
$pro[$itID] = ((int) $pro[$itID] + (int) $item->get_quantity());
}
}
}
}
}
}
?>