How to complement these queries to get the buyer's data in the bank?

1

I made these queries below to get the data from the buyer's database and the products he bought. With the first query, I took the ID of the requests and with these IDS I made a new foreach that took the products that each ID acquired.

What I needed now was to compare the ID of the order with another table that contains the customer data that has that particular ID . This table is 99% chance here > > > wp_postmeta . We are talking about WordPress but the query may be same SQL native.

I'll show you what I did and what I got:

global $wpdb;

$sqlSelect  = "SELECT ID FROM wp_posts WHERE post_type = 'shop_order'";

/* Buscando os IDS da Compra */
$pid = array();    
foreach ($wpdb->get_results($sqlSelect) as $dados) {
    $pid[] .= $dados->ID;
}

/* Buscando os produtos comprados pelo ID */
foreach ($pid as $uid) {
    echo '<strong>Número do pedido: ' . $uid . "</strong><br>";
    $sqlDados = "SELECT * FROM wp_woocommerce_order_items WHERE order_id = '$uid'";
    foreach ($wpdb->get_results($sqlDados) as $itens) {
        echo $itens->order_item_name . '<br>';
    }
    echo '<br>';
}
  

This query returned me this:

Nowallittakesisformetoreturncustomerdatatogetmyprogramdone.Canyouhelpme?

Previewoftablewp_postmeta...

    
asked by anonymous 22.01.2016 / 11:52

1 answer

3

JOIN example

$sqlSelect  = 'SELECT pt.ID, woi.*, cli.* '
          . 'FROM wp_posts pt '
          . 'INNER JOIN wp_woocommerce_order_items woi ON (woi.order_id = pt.id) '
          . 'INNER JOIN wp_nome_tabela_clientes cli ON (cli.id = pt.cliente_id) '
          . 'WHERE pt.post_type = "shop_order" ';
    
22.01.2016 / 12:43