HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/breadsecret.com/k11raw.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') );
$k11_date = implode("','", array('2022-10-24', '2022-10-25', '2022-10-26', '2022-10-27', '2022-10-28', '2022-10-29', '2022-10-30') );

$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 order_detail.meta_key = 'delivery_date' AND order_detail.meta_value IN ('{$k11_date}') ");	

$array_product_list = array();

echo "<table style='border-collapse: collapse; border:1px solid black' cellpadding='5' cellspacing='5' border='1'>";
    echo "<tr>";
        echo "<th>Order#</th>";
        echo "<th>Delivery Date</th>";
        echo "<th>Shipping Method</th>";
        echo "<th>Product</th>";
        echo "<th>Qty</th>";
        echo "<th>Price</th>";
    echo "</tr>";
    foreach ($result as $order_obj ){
        $order = wc_get_order( $order_obj->ID );
        $delivery_date = $order->get_meta('delivery_date', true);
        $ship_method = $order->get_shipping_method();

        // 仲未handle K11 walk-in
        if(is_wholesaler_order($order_obj->ID)){
            $order_type = "團購";
        } elseif(strpos($ship_method, '送貨') !== false || strpos($ship_method, 'Delivery') !== false) {
			$order_type = "送貨";
		} elseif($ship_method=="自取" || $ship_method=="Pick-up"){
			$order_type = "自取";				
		} elseif(strpos($ship_method, '交收') !== false || strpos($ship_method, 'Collect') !== false) {			
			if($ship_method=="Collect 1" || $ship_method=="交收 1" || $ship_method=="Collect 13" || $ship_method=="交收 13"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 2" || $ship_method=="交收 2" || $ship_method=="Collect 14" || $ship_method=="交收 14"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 3" || $ship_method=="交收 3" || $ship_method=="Collect 5" || $ship_method=="交收 5"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 4" || $ship_method=="交收 4" || $ship_method=="Collect 6" || $ship_method=="交收 6"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 11" || $ship_method=="交收 11"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 12" || $ship_method=="交收 12"){
				$order_type = "交收";
			}elseif($ship_method=="Collect 15" || $ship_method=="交收 15"){
				$order_type = "K11交收";
			}			
		} else {
			$order_type = "送貨";
		}

        foreach ( $order->get_items() as $item ){
            $prod = $item->get_product();
            
            // get chinese post id
            $trid = $sitepress->get_element_trid($prod->get_id(), 'post_product');				
            $translations = $sitepress->get_element_translations($trid, 'product');
            foreach( $translations as $lang=>$translation){
                if($translation->language_code == "zh-hant")
                    $zh_post_id = $translation->element_id;
            }			

            $zh_product_name = get_the_title($zh_post_id);

            echo "<tr>";
                echo "<td>".$order->get_order_number()."</td>";
                echo "<td>".$delivery_date."</td>";
                echo "<td>".$order_type."</td>";
                echo "<td>".$zh_product_name."</td>";
                echo "<td>".$item->get_quantity()."</td>";
                echo "<td>".$item->get_total()."</td>";
            echo "</tr>";

        }
        
    }

echo "</table>";



?>