WooCommerce display order product name in my account

I’m using WooCommerce 2.0 and I would like to retrieve and display the ordered product name in the myaccount.php page, alongside the order number.

So if this is the default display in myaccount.php:

Read More
ORDER   DATE    STATUS  TOTAL   ACTIONS LICENSING
#521    August 19, 2014 Completed   $99.99 for 1 item   VIEW

I’d like to change it to:

ORDER               DATE    STATUS  TOTAL   ACTIONS LICENSING
#521-ProductName    August 19, 2014 Completed   $99.99 for 1 item   VIEW

Can anyone offer any suggestions on how to retrieve the order product name? I am confused on how to do this.

Thanks!

Related posts

Leave a Reply

2 comments

  1. You can do it after making some changes in your my-orders.php

    you need my-orders.php. Place a copy in your theme folder to make it update proof.

    //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
    
  2. $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!
    }
    

    And in order to get more details of the order you can use the below code.

    Assuming $post->ID is the id of the product you want to display the orders containing, this is what you need:

    $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; 
        }   
    }