WooCommerce Get Item Meta from All Orders

后端 未结 2 483
日久生厌
日久生厌 2021-02-06 15:13

I am trying to display all Order Items (with the Item Meta) for All completed orders from the WooCommerce plugin. I also want to limit the display to 10 order items only. I have

2条回答
  •  心在旅途
    2021-02-06 15:44

    Something like this should limit the amount of items displayed to 10:

     'shop_order',
        'post_status' => 'publish',
        'posts_per_page' => 10,
        'tax_query' => array(
            array(
                'taxonomy' => 'shop_order_status',
                'field' => 'slug',
                'terms' => array('completed')
            )
        )
    );
    $orders=get_posts($args);
    $i=0;
    foreach($orders as $o):
        if($i>10){
            break;
        }
        $order_id = $o->ID;
        $order = new WC_Order($order_id);
        foreach( $order->get_items() as $item ):
            if($i>10){
                break;
            }
            $i++;
            $date = $item['Booking Date'];
            $time = $item['Booking Time'];
            $fname = $item['First Name - First Name'];
            $church = $item['Church Information - Church Name'];
            $city = $item['Church Information - City'];
            $state = $item['Church Information - State'];
        ?>
            

    If I understand what you're looking for correctly that should do the trick.

提交回复
热议问题