add_action('wp_ajax_get_crm_stats', function() { if (!current_user_can('manage_woocommerce')) { wp_send_json_error('Accès refusé'); } check_ajax_referer('get_crm_stats', 'nonce'); $period = $_POST['period'] ?? 'today'; $date_from = null; $date_to = current_time('mysql'); switch ($period) { case 'today': $date_from = date('Y-m-d 00:00:00'); break; case 'yesterday': $date_from = date('Y-m-d 00:00:00', strtotime('-1 day')); $date_to = date('Y-m-d 23:59:59', strtotime('-1 day')); break; case '7days': $date_from = date('Y-m-d 00:00:00', strtotime('-6 days')); break; case '30days': $date_from = date('Y-m-d 00:00:00', strtotime('-29 days')); break; case 'thismonth': $date_from = date('Y-m-01 00:00:00'); break; case 'custom': // à implémenter plus tard $date_from = date('Y-m-d 00:00:00'); break; default: $date_from = date('Y-m-d 00:00:00'); } $args = [ 'limit' => -1, 'status' => ['wc-completed', 'wc-expedie', 'wc-failed'], 'date_created' => $date_from ? "{$date_from}...{$date_to}" : null, 'return' => 'ids' ]; $order_ids = wc_get_orders($args); $total = count($order_ids); $completed = $shipped = $failed = 0; foreach ($order_ids as $order_id) { $order = wc_get_order($order_id); if (!$order) continue; $status = $order->get_status(); if ($status === 'completed') $completed++; if ($status === 'expedie') $shipped++; if ($status === 'failed') $failed++; } wp_send_json_success([ 'total_orders' => $total, 'completed' => $completed, 'shipped' => $shipped, 'failed' => $failed ]); });
Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /home/mysticke151/public_html/wp-includes/capabilities.php:911 Stack trace: #0 /home/mysticke151/public_html/wp-content/plugins/mystickers-crm-plus/includes/import.php(4): current_user_can('manage_woocomme...') #1 /home/mysticke151/public_html/wp-content/plugins/mystickers-crm-plus/mystickers-crm-plus.php(14): require_once('/home/mysticke1...') #2 /home/mysticke151/public_html/wp-settings.php(545): include_once('/home/mysticke1...') #3 /home/mysticke151/public_html/wp-config.php(105): require_once('/home/mysticke1...') #4 /home/mysticke151/public_html/wp-load.php(50): require_once('/home/mysticke1...') #5 /home/mysticke151/public_html/wp-blog-header.php(13): require_once('/home/mysticke1...') #6 /home/mysticke151/public_html/index.php(17): require('/home/mysticke1...') #7 {main} thrown in /home/mysticke151/public_html/wp-includes/capabilities.php on line 911