File: /var/www/html/breadsecret.com/testFunc.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('wp-load.php');
session_start();
date_default_timezone_set("Asia/Hong_Kong");
global $wpdb, $sitepress;
$post_status = implode("','", array('wc-pending', 'wc-processing', 'wc-completed'));
//get all orders
$result = $wpdb->get_results("SELECT * FROM wp_posts order_master left join wp_postmeta order_detail ON order_master.ID = order_detail.post_id WHERE order_master.post_type = 'shop_order' AND order_master.post_status IN ('{$post_status}') AND post_date LIKE '2023%' GROUP BY ID");
$total_qty = 0;
echo "<table>";
echo "<tr>";
echo "<td>Order#</td><td>Order Date</td><td>Product</td><td>QTY</td>";
echo "</tr>";
foreach ($result as $order_obj) {
$order = wc_get_order($order_obj->ID);
$number = $order->get_order_number();
$date = $order->get_date_created();
foreach ($order->get_items() as $item) {
$product_name = $item->get_name();
$total_qty += $item->get_quantity();
echo "<tr>";
echo "<td>".$number."</td>";
echo "<td>".$date."</td>";
echo "<td>".$product_name."</td>";
echo "<td>".$item->get_quantity()."</td>";
echo "</tr>";
}
}
echo "</table>";