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
...