doudiza9154 2013-12-26 16:00
浏览 111
已采纳

woocommerce买家在前端发送电子邮件

i have created Website using Wordpress and WooCommerce Plugin, and i have success making users post products from frontend,
i want to display product orders

as you can see in this image
detailed images

i success showing total sales for the product, now i want to show all buyers infomations for the product/

so far i have got this code

<?php

 $p = $post->ID;
 $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;
 //print_r($customer_orders);
 foreach ($customer_orders as $customer_order) {
   $order = new WC_Order();
   $order->populate($customer_order);
   $orderdata = (array) $order;
   $fields = array_values($orderdata);
   //print_r($fields);
   echo 'Status: '.$fields[1];                           
   echo '<br>Date  : '.$fields[2];                           
   echo '<br>Email  : '.$fields[16];                           

 }

?>

This Code is Working Fine But it Show details about all products

What i Want is: to show informations about about product depending on product ID

so i want to edit this code to get results depending on post->id

$p = $post->ID;
     $args = array(
       'post_type' => 'shop_order',
       'post_status' => 'publish',
       'meta_key' => '_customer_user',
       'posts_per_page' => '-1'
     );
  • 写回答

2条回答 默认 最新

  • doujing5846 2014-01-06 19:37
    关注

    Ok, so reading your question and assuming $post->ID is the id of the product you want to display the orders containing, this is what you need:

    <?php
    $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; 
        }   
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元