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
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'
);
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:
If I understood your question well, maybe you can try this. But you have to make sure that
$post
is refering to the order.You can read the doc of the WP_Query() function here : http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters