WooCommerce – Show orders for a specific product ? [closed]

Eric based on your code I wrote to meet my needs, for those who want to follow:

Eric com base em seu código eu escrevi o para atender as minhas necessidades, para quem quiser segue abaixo:

<?php
global $wpdb;   
$produto_id = 22777; // ID do produto
$consulta = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_itemmeta woim 
        LEFT JOIN {$wpdb->prefix}woocommerce_order_items oi 
        ON woim.order_item_id = oi.order_item_id 
        WHERE meta_key = '_product_id' AND meta_value = %d
        GROUP BY order_id;";
$order_ids = $wpdb->get_col( $wpdb->prepare( $consulta, $produto_id ) );
if( $order_ids ) {
                 $args = array(
                'post_type'       =>'shop_order',
                'post__in'   => $order_ids,
                'post_status'    => 'publish',
                'posts_per_page' =>  20,
                'order'          => 'DESC',             
                'tax_query' => array( 
                array( 'taxonomy' => 'shop_order_status',
                       'field' => 'slug',
                       'terms' => array ('Pending' , 'Failed' , 'Processing' , 'Completed', 'On-Hold' , 'Cancelled' , 'Refunded')
                      ) 
                    )           
                );
                $orders = new WP_Query( $args );
                }
?>               
<table>
            <thead>
                <tr>
                    <th ><?php _e('ID do Pedido:', ''); ?></th>
                    <th ><?php _e('sku:', ''); ?></th>
                    <th ><?php _e('Categoria:', ''); ?></th>
                    <th ><?php _e('Produto:', ''); ?></th>
                    <th ><?php _e('Data Consolidada da compra:', ''); ?></th>
                    <th ><?php _e('Valor:', ''); ?></th>
                    <th ><?php _e('Nome:', ''); ?></th>
                    <th ><?php _e('Tel:', ''); ?></th>
                    <th ><?php _e('End:', ''); ?></th>
                    <th ><?php _e('Cidade:', ''); ?></th>
                    <th ><?php _e('Estado:', ''); ?></th>
                    <th ><?php _e('E-mail:', ''); ?></th>
                    <th ><?php _e('status:', ''); ?></th>
                </tr>
            </thead>
            <tbody>      
                <?php
                while ( $orders->have_posts() ) : $orders->the_post(); 
                $order_id = $orders->post->ID; 
                $order = new WC_Order($order_id);            
                ?> 
                <tr>
                     <td>
                        <?php
                           //  Exibe o ID do pedido 
                         if ($order->id) : ?>
                            <a href="https://wordpress.stackexchange.com/questions/194289/<?php echo esc_url( home_url("https://wordpress.stackexchange.com/" ) ); ?>wp-admin/post.php?post=<?php echo $order->id; ?>&action=edit" target="_blank"><?php echo $order->id; ?></a><?php endif;?>
                    </td>
                    <td>
                        <?php
                            // Exibe o SKU
                            if (sizeof($order->get_items())>0)  { foreach($order->get_items() as $item) 
                            { $_product = get_product( $item['product_id'] );   echo '' . $_product->sku . '';   }  }
                        ?> 
                    </td>
                    <td>
                        <?php
                            // Exibe a Categoria do produto
                            if (sizeof($order->get_items())>0)  { foreach($order->get_items() as $item)
                            { $_product = get_product( $item['product_id'] ); 
                            echo $_product->get_categories( ', ', '' . _n( '', '', $size, 'woocommerce' ) . ' ', '  ' ); } }
                        ?>
                    </td>

                    <td>
                        <?php
                            // Exibe o nome do produto
                           if (sizeof($order->get_items())>0)   { foreach($order->get_items() as $item) 
                           { $_product = get_product( $item['product_id'] ); echo '' . $item['name'] . '';  } }
                        ?>
                    </td>                   
                    <td>
                        <?php 
                        // Exibe a data da copmpra
                         echo the_time('d/m/Y'); ?>
                    </td>
                    <td>
                        <?php 
                        // Exibe o valor da compra + a formatação do preço
                        if ($order->order_total): $preco_format=($order->order_total);?>
                        <?php echo $trata_preco=number_format($preco_format, 2, ",", "."); ?><?php endif; ?>
                    </td>
                    <td>
                        <?php 
                         // Exibe o nome e sobrenome do cliente
                         if ($order->billing_first_name) : ?><?php echo $order->billing_first_name; ?><?php endif; ?>
                        <?php if ($order->billing_last_name) : ?><?php echo $order->billing_last_name; ?><?php endif; ?>
                    </td>
                  <td>
                        <?php 
                         // Exibe o telefone do cliente
                         if ($order->billing_phone) : ?><?php echo $order->billing_phone; ?><?php endif; ?>
                    </td>
                    <td>
<?php // Exibe o endereço do cliente
 if ($order->billing_address_1): ?><?php echo $order->billing_address_1; ?>, <?php endif; ?> <?php if ($order->billing_number): ?> <?php echo $order->billing_number; ?><?php endif; ?> <?php if ($order->billing_address_2): ?><?php echo $order->billing_address_2; ?> <?php endif; ?><?php if ($order->billing_neighborhood): ?>Bairro: <?php echo $order->billing_neighborhood; ?><?php endif; ?> <?php if ($order->billing_postcode): ?>Cep: <?php echo $order->billing_postcode; ?><?php endif; ?>
                    </td>               
                    <td>
                        <?php 
                        // Exibe a cidade do cliente
                        if ($order->billing_city): ?><?php echo $order->billing_city; ?><?php endif; ?>
                    </td>
                    <td>
                        <?php 
                        // Exibe o estado do cliente
                        if ($order->billing_state): ?><?php echo $order->billing_state; ?><?php endif; ?>
                    </td>
                    <td>
                        <?php 
                        // Exibe o e-mail do cliente
                         if ($order->billing_email) : ?><?php echo $order->billing_email; ?><?php endif; ?>
                    </td>
                    <td>
                        <?php 
                        // Exibe o status do pedidodo cliente
                         if ($order->status) : ?><?php echo $order->status; ?><?php endif; ?>
                    </td>
               </tr> 

            <?php endwhile; ?>
                   <?php wp_reset_query(); ?> 
            </tbody>
        </table>