-1,
'orderby' => 'date',
'order' => 'DESC',
'status' => array_keys( wc_get_order_statuses() ),
] );/* ── 2. Stats rapides ── */
$stat_total = count( $orders );
$stat_pending = 0;
$stat_devis = 0;
$stat_revenue = 0.0;foreach ( $orders as $o ) {
$s = $o->get_status();
if ( in_array( $s, [ 'pending', 'on-hold' ], true ) ) $stat_pending++;
if ( $s === 'ywraq-new' ) $stat_devis++;
if ( $s === 'completed' ) $stat_revenue += (float) $o->get_total();
}/* ── 3. Correspondance statut → classe badge ── */
$badge_map = [
'pending' => 'badge-amber',
'processing' => 'badge-blue',
'completed' => 'badge-green',
'cancelled' => 'badge-red',
'refunded' => 'badge-purple',
'failed' => 'badge-rose',
'on-hold' => 'badge-orange',
'ywraq-new' => 'badge-sky',
];ob_start();
/* ── 4. CDN (chargés une seule fois via flag) ── */
static $cdn_done = false;
if ( ! $cdn_done ) :
$cdn_done = true; ?>
Chargement des commandes…
| N° Cmd | Date | Client | Email | Téléphone | Statut | Total | Actions |
get_id();
$status = $order->get_status();
$date_obj = $order->get_date_created();
$date_raw = $date_obj ? $date_obj->date( 'Y-m-d H:i' ) : '';
$date_ts = $date_obj ? $date_obj->getTimestamp() : 0;
$date_disp = $date_obj ? $date_obj->date( 'd/m/Y H:i' ) : '—';
$total_raw = (float) $order->get_total();
$total_fmt = wc_price( $total_raw );
$status_label = wc_get_order_status_name( $status );
$badge_cls = $badge_map[ $status ] ?? 'badge-gray';$client = trim( $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() );
$email = $order->get_billing_email();
$phone = $order->get_billing_phone();
$message = $order->get_customer_note();
$company = $order->get_billing_company();/* Champs spéciaux devis YWRAQ */
if ( $status === 'ywraq-new' ) {
$tbl = $wpdb->prefix . 'wc_orders_meta';
$mn = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $tbl WHERE order_id=%d AND meta_key='ywraq_customer_name'", $oid ) );
$me = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $tbl WHERE order_id=%d AND meta_key='ywraq_customer_email'", $oid ) );
if ( $mn ) $client = $mn;
if ( $me ) $email = $me;$ser = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $tbl WHERE order_id=%d AND meta_key='ywraq_other_email_fields'", $oid ) );
$des = maybe_unserialize( $ser );
if ( is_array( $des ) ) {
$phone = $des['Téléphone'] ?? $phone;
$message = $des['Message'] ?? $message;
}
$dm = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $tbl WHERE order_id=%d AND meta_key='ywraq_customer_message'", $oid ) );
if ( ! empty( $dm ) ) $message = $dm;
}/* Avatar initiales */
$parts = explode( ' ', trim( $client ) );
$initials = strtoupper( mb_substr( $parts[0] ?? '?', 0, 1 ) . mb_substr( $parts[1] ?? '', 0, 1 ) );/* Adresses */
$addr_f = implode( ', ', array_filter( [
$order->get_billing_address_1(),
$order->get_billing_city(),
$order->get_billing_postcode(),
$order->get_billing_country(),
] ) );
$addr_l = implode( ', ', array_filter( [
$order->get_shipping_address_1(),
$order->get_shipping_city(),
$order->get_shipping_postcode(),
$order->get_shipping_country(),
] ) );/* Produits (HTML table) */
$prod_rows = '';
foreach ( $order->get_items() as $item ) {
$prod_rows .= sprintf(
'| %s | %d | %s |
',
esc_html( $item->get_name() ),
$item->get_quantity(),
wp_strip_all_tags( wc_price( $item->get_total() ) )
);
}/* HTML détail (expand) */
$det = '👤 Informations client
' . esc_html( $client ?: '—' ) . '
' . esc_html( $email ?: '—' ) . '
' . esc_html( $phone ?: '—' ) . '
🏢 Société
' . esc_html( $company ?: '—' ) . '
📍 Adresse facturation
' . esc_html( $addr_f ?: '—' ) . '
🚚 Adresse livraison
' . esc_html( $addr_l ?: '—' ) . '
💳 Mode de paiement
' . esc_html( $order->get_payment_method_title() ?: '—' ) . '
💬 Message client
' . nl2br( esc_html( $message ?: '—' ) ) . '
📦 Produits commandés
| Produit | Qté | Total |
' . $prod_rows . '
';/* Données print JSON (stockées sur la ligne) */
$print_json = wp_json_encode( [
'num' => $order->get_order_number(),
'date' => $date_disp,
'status' => $status_label,
'total' => wp_strip_all_tags( $total_fmt ),
'client' => $client,
'email' => $email,
'phone' => $phone,
'company' => $company,
'addr_f' => $addr_f,
'addr_l' => $addr_l,
'payment' => $order->get_payment_method_title(),
'message' => $message,
], JSON_HEX_QUOT | JSON_HEX_APOS );$view_url = $order->get_edit_order_url();
?>|
+ |
#get_order_number() ); ?> |
| | | —'; ?> |
|
| |