WooCommerce – Bestellungen für ein bestimmtes Produkt anzeigen?

Wie sieht man Bestellungen für ein bestimmtes Produkt in WooCommerce mit sku oder Produktnamen? Was ich bisher habe, ist das, aber es funktioniert nicht .. Weiß jemand wie?

'shop_order', 'post_status' => 'publish', 'posts_per_page' => 50, 'order' => 'DESC', 'item_meta' => array ( '_sku' => 'ABCD', ), 'tax_query' => array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array ('Pending' , 'Failed' , 'Processing' , 'Completed', 'On-Hold' , 'Cancelled' , 'Refunded') ) ) ); ?>  have_posts() ) : $loop->the_post(); $order_id = $loop->post->ID; $order = new WC_Order($order_id); ?> 
id) : ?>id; ?> get_items())>0) { foreach($order->get_items() as $item) { $_product = get_product( $item['product_id'] ); echo '' . $_product->sku . ''; } } ?> get_items())>0) { foreach($order->get_items() as $item) { $_product = get_product( $item['product_id'] ); echo $_product->get_categories( ', ', '' . _n( '', '', $size, 'woocommerce' ) . ' ', ' ' ); } } ?> get_items())>0) { foreach($order->get_items() as $item) { $_product = get_product( $item['product_id'] ); echo '' . $item['name'] . ''; } } ?> order_total): $preco_format=($order->order_total);?> billing_first_name) : ?>billing_first_name; ?> billing_last_name) : ?>billing_last_name; ?> billing_email) : ?>billing_email; ?> status) : ?>status; ?>

Solutions Collecting From Web of "WooCommerce – Bestellungen für ein bestimmtes Produkt anzeigen?"

Eric basierend auf Ihrem Code Ich schrieb, um meine Bedürfnisse zu erfüllen, für diejenigen, die folgen wollen:

Eric hat sich für den Kundendienst entschieden, um Kunden zu unterstützen, die folgende Voraussetzungen erfüllen müssen:

 < ?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 ); } ?>  < ?php while ( $orders->have_posts() ) : $orders->the_post(); $order_id = $orders->post->ID; $order = new WC_Order($order_id); ?>  < ?php endwhile; ?> < ?php wp_reset_query(); ?> 
< ?php _e('ID do Pedido:', ''); ?> < ?php _e('sku:', ''); ?> < ?php _e('Categoria:', ''); ?> < ?php _e('Produto:', ''); ?> < ?php _e('Data Consolidada da compra:', ''); ?> < ?php _e('Valor:', ''); ?> < ?php _e('Nome:', ''); ?> < ?php _e('Tel:', ''); ?> < ?php _e('End:', ''); ?> < ?php _e('Cidade:', ''); ?> < ?php _e('Estado:', ''); ?> < ?php _e('E-mail:', ''); ?> < ?php _e('status:', ''); ?>
< ?php // Exibe o ID do pedido if ($order->id) : ?> < ?php echo $order->id; ?>< ?php endif;?> < ?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 . ''; } } ?> < ?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' ) . ' ', ' ' ); } } ?> < ?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'] . ''; } } ?> < ?php // Exibe a data da copmpra echo the_time('d/m/Y'); ?> < ?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; ?> < ?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; ?> < ?php // Exibe o telefone do cliente if ($order->billing_phone) : ?>< ?php echo $order->billing_phone; ?>< ?php endif; ?> < ?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; ?> < ?php // Exibe a cidade do cliente if ($order->billing_city): ?>< ?php echo $order->billing_city; ?>< ?php endif; ?> < ?php // Exibe o estado do cliente if ($order->billing_state): ?>< ?php echo $order->billing_state; ?>< ?php endif; ?> < ?php // Exibe o e-mail do cliente if ($order->billing_email) : ?>< ?php echo $order->billing_email; ?>< ?php endif; ?> < ?php // Exibe o status do pedidodo cliente if ($order->status) : ?>< ?php echo $order->status; ?>< ?php endif; ?>

Feito!

Realmente com o WP_Query no da data … sabre essa informação é necessário usuizar 2 tabelas tun WooCommerce.

Então montei a função pra você … ela busca pélo postID do produto e retorna oder objecto dos pedidos pra você fazer o loop normal.

É só coloca-la no sé function.php e usa-lær qualquer lugar que quiser! Aqui funcionou bem! Se algo der errado ai, ich bin eine gute Fee!

 function retorna_idpedidos_por_produtoid($produtoId) { global $wpdb; $tabelaOrderItemMeta = $wpdb->prefix . 'woocommerce_order_itemmeta'; $tabelaOrderItems = $wpdb->prefix . 'woocommerce_order_items'; $resultadoSelect = $wpdb->get_results( $wpdb->prepare( "SELECT b.order_id FROM {$tabelaOrderItemMeta} a, {$tabelaOrderItems} b WHERE a.meta_key = '_product_id' AND a.meta_value = %s AND a.order_item_id = b.order_item_id ORDER BY b.order_id DESC", $produtoId ) ); if($resultadoSelect) { $resultado = array(); foreach($resultadoSelect as $item) array_push($resultado, $item->order_id); if($resultado) { $args = array( 'post_type' =>'shop_order', 'post_status' => 'publish', 'posts_per_page' => -1, 'post__in' => $resultado, 'order' => 'DESC' ); $query = new WP_Query($args); return $query; } } } 

Pronto, agora é só fazer o Schleife, zum Beispiel:

 < ?php $pedidos = retorna_idpedidos_por_produtoid(33); ?> < ?php if($pedidos && $pedidos->have_posts()): ?> < ?php while ($pedidos->have_posts()): $pedidos->the_post(); ?> 
 < ?php the_ID(); ?> 

< ?php endwhile ?> < ?php endif; ?>

Teste aí, espero que dê certo! Abs!