Get customers name who paid in product page
-
Hello there, im trying to do a loop with wp_query but i cant get the names from customers who paid for the product on its product page..
what i have so far is:
$p = $post->ID; $args = array( 'p' => $p, 'numberposts' => -1, 'meta_key' => '_customer_user', 'post_type' => 'shop_order', 'post_status' => 'publish', 'tax_query'=>array( array( 'taxonomy' =>'shop_order_status', 'field' => 'slug', 'terms' =>'wc-completed' ) ) ); $my_query = new WP_Query($args); if ( $my_query->have_posts()) : while ( $my_query->have_posts() ) : $my_query->the_post(); $customer_order = $my_query->post; $order = new WC_Order(); $order->populate($customer_order); $orderdata = (array)$order; $fields = array_values($orderdata); echo '<pre>'; print_r($fields); exit; $user = get_user_by( 'id', $fields[2] ); echo $user->first_name . ' ' . $user->last_name.'<br>'; endwhile; endif;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get customers name who paid in product page’ is closed to new replies.