WooCommerce Get Item Meta from All Orders

后端 未结 2 485
日久生厌
日久生厌 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:54

    I don't think wordpress provide you such type of query. You have to build your own logic to do this. Hope this may help you...

    $args = array(
       'post_type' => 'shop_order',
       'post_status' => 'publish',
       'posts_per_page' => -1,
       'tax_query' => array(
           array(
                'taxonomy' => 'shop_order_status',
                'field' => 'slug',
                'terms' => array('completed')
                )
              )
       );
    
             $count = 0;
             $loop = new WP_Query( $args );
    
                while ( $loop->have_posts() ) : $loop->the_post();
                    $order_id = $loop->post->ID;
                    $order = new WC_Order($order_id);
    
                    foreach( $order->get_items() as $item ) {   
    
                        if( $count > 10){
                           break 2; //break both loops 
                        } 
                        $count++;
                        $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'];
                    ?>
    
                        

提交回复
热议问题