问题是您显示的是订单信息,而不是项目信息。您希望根据项目打印内容,如下所示:
echo \'<h2>Previous Donations for this Nonprofit</h2>\';
foreach (get_posts(\'post_type=shop_order&numberposts=-1&post_status=wc-completed\') as $order) {
$order = new WC_Order($order->ID);
foreach($order->get_items(\'line_item\') as $item) {
if ($post->ID == $item[\'product_id\'] || $post->ID == $item[\'variation_id\']) {
echo \'<br>Date: \'.$order->order_date;
echo \'<br>Name: \'.$order->billing_first_name . \' \' .$order->billing_last_name;
echo \'<br>Email: \'.$order->billing_email;
echo \'<br>Order Total: $\'.$order->get_line_total( $item );
}
}
}
我不确定您运行的是哪个版本的WooCommerce,但我在尝试查询post\\u状态为publish的帖子时出错。版本2.2+希望您根据其专有的post状态i进行检查。你可以看到上面的反映。