
Generare la lista dei clienti in WooCommerce
<?php
$_customer_orders = '';
$_customer_orders_products = '';
$query = new WC_Order_Query( array(
'limit' => -1,
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
'date_query' => array(
array(
)
)
) );
$orders = $query->get_orders();
foreach ($orders as $order_id){
$_wc_get_order = wc_get_order($order_id);
$order_obj = new WC_Order( $order_id );
$email = $order_obj->billing_email;
$user_id = get_post_meta($order_id, '_customer_user', true);
if($email !== ''){
$_date_formatted = $order_obj->get_date_created();
$_customer_orders .= $order_id.','. $order_obj->get_billing_first_name().','.$email.PHP_EOL;
//# products
$_order_obj = wc_get_order($order_id);
$_items = $_order_obj->get_items();
foreach ( $_items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
if ( !empty($product_variation_id) ) {
$variation = wc_get_product($product_variation_id);
$variation_get_title = $variation->get_title();
}else{
$variation_get_title = '';
}
$_customer_orders_products .= $order_id.','. $order_obj->get_billing_first_name().','.$email.','.$product_id.','.$product_name.' '.$variation_get_title.PHP_EOL;
}
}
}