我使用WooCommerce 2.0,我想检索并myaccount.php页面显示订购的产品名称,旁边的订单号。
因此,如果这是在myaccount.php默认显示:
ORDER DATE STATUS TOTAL ACTIONS LICENSING
#521 August 19, 2014 Completed $99.99 for 1 item VIEW
我想将其更改为:
ORDER DATE STATUS TOTAL ACTIONS LICENSING
#521-ProductName August 19, 2014 Completed $99.99 for 1 item VIEW
任何人都可以提供关于如何获取订单产品名称有什么建议? 我是如何做到这一点困惑。
谢谢!
你可以让你的我的,orders.php一些变化后做
你需要我,orders.php。 放置一个副本在你的主题文件夹,使其更新证明。
//Add the following code in the customer_order loop
foreach($order->get_items() as $item) {
$product_name = $item['name'];
}
<?php echo $product_name;?> //echo product name
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'meta_key' => '_customer_user',
'posts_per_page' => '-1'
);
$my_query = new WP_Query($args);
$customer_orders = $my_query->posts;
foreach ($customer_orders as $customer_order) {
$order = new WC_Order();
$order->populate($customer_order);
$orderdata = (array) $order;
// $orderdata Array will have Information. for e.g Shippin firstname, Lastname, Address ... and MUCH more.... Just enjoy!
}
而为了让你可以使用下面的代码顺序的更多细节。
假设$后> ID是要显示包含订单产品的ID,这是你所需要的:
$products = array();
foreach (get_posts('post_type=shop_order&numberposts=-1&post_status=publish') as $order) {
$order = new WC_Order($order->ID);
foreach($order->get_items('line_item') as $item) {
$product_id = (!empty($item['variation_id'])) ? $item['variation_id'] : $item['product_id'];
$products[] = $product_id;
}
if (in_array($post->ID,$products)) {
echo 'Status: '.$order->order_status;
echo '<br>Date : '.$order->order_date;
echo '<br>Email : '.$order->billing_email;
}
}