Php WooCommerce在我的帐户中显示订单产品名称
我使用的是WooCommerce 2.0,我希望在myaccount.php页面中检索并显示订购的产品名称以及订单号 因此,如果这是myaccount.php中的默认显示:Php WooCommerce在我的帐户中显示订单产品名称,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我使用的是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
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
有人能就如何检索订单产品名称提供建议吗?我不知道该怎么做
谢谢
$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!
}
为了获得订单的更多详细信息,您可以使用以下代码
假设$post->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;
}
}
$products=array();
foreach(获取发布('post\u type=shop\u order&numberposts=-1&post\u status=publish')作为$order){
$order=新WC\U订单($order->ID);
foreach($order->get_items('line_item')作为$item){
$product_id=(!empty($item['variation_id'])?$item['variation_id']:$item['product_id'];
$products[]=$product\U id;
}
if(在数组中($post->ID,$products)){
回显“状态:”。$order->order_状态;
回显'
日期:'.$order->order\u日期;
回显“
电子邮件:”.$order->计费电子邮件;
}
}
为了获得订单的更多详细信息,您可以使用以下代码
假设$post->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;
}
}
$products=array();
foreach(获取发布('post\u type=shop\u order&numberposts=-1&post\u status=publish')作为$order){
$order=新WC\U订单($order->ID);
foreach($order->get_items('line_item')作为$item){
$product_id=(!empty($item['variation_id'])?$item['variation_id']:$item['product_id'];
$products[]=$product\U id;
}
if(在数组中($post->ID,$products)){
回显“状态:”。$order->order_状态;
回显'
日期:'.$order->order\u日期;
回显“
电子邮件:”.$order->计费电子邮件;
}
}
您可以在my-orders.php中进行一些更改后执行此操作
您需要my-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
//在客户订单循环中添加以下代码
foreach($order->get_items()作为$item){
$product_name=$item['name'];
}
//echo产品名称
您可以在my-orders.php中进行一些更改后执行此操作
您需要my-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
//在客户订单循环中添加以下代码
foreach($order->get_items()作为$item){
$product_name=$item['name'];
}
//echo产品名称