admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('wpdd_order_manager'), 'confirm_cancel' => __('Are you sure you want to cancel this order? This action cannot be undone.', 'wp-digital-download'), 'confirm_refund' => __('Are you sure you want to process this refund? The customer will lose access to the product.', 'wp-digital-download'), 'confirm_release' => __('Are you sure you want to release these earnings immediately?', 'wp-digital-download') )); } public static function render_page() { global $wpdb; // Get filter parameters $status_filter = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : 'all'; $creator_filter = isset($_GET['creator']) ? intval($_GET['creator']) : 0; $date_from = isset($_GET['date_from']) ? sanitize_text_field($_GET['date_from']) : date('Y-m-d', strtotime('-30 days')); $date_to = isset($_GET['date_to']) ? sanitize_text_field($_GET['date_to']) : date('Y-m-d'); // Build query $where_conditions = array('1=1'); $query_params = array(); if ($status_filter !== 'all') { $where_conditions[] = 'o.status = %s'; $query_params[] = $status_filter; } if ($creator_filter > 0) { $where_conditions[] = 'p.post_author = %d'; $query_params[] = $creator_filter; } if ($date_from) { $where_conditions[] = 'DATE(o.purchase_date) >= %s'; $query_params[] = $date_from; } if ($date_to) { $where_conditions[] = 'DATE(o.purchase_date) <= %s'; $query_params[] = $date_to; } $where_clause = implode(' AND ', $where_conditions); // Get orders with earnings status $orders = $wpdb->get_results($wpdb->prepare( "SELECT o.*, p.post_title as product_name, u.display_name as creator_name, e.payout_status, e.available_at, e.creator_earning, e.id as earning_id FROM {$wpdb->prefix}wpdd_orders o LEFT JOIN {$wpdb->posts} p ON o.product_id = p.ID LEFT JOIN {$wpdb->users} u ON p.post_author = u.ID LEFT JOIN {$wpdb->prefix}wpdd_creator_earnings e ON o.id = e.order_id WHERE $where_clause ORDER BY o.purchase_date DESC LIMIT 100", $query_params )); // Get creators for filter $creators = get_users(array('role' => 'wpdd_creator')); ?>

()

order_number); ?>
#id); ?>
customer_name); ?>
customer_email); ?>
product_name); ?>
ID: product_id); ?>
creator_name); ?> amount); ?> purchase_date))); ?> status) { case 'completed': $status_class = 'notice-success'; break; case 'cancelled': case 'failed': $status_class = 'notice-error'; break; case 'pending': $status_class = 'notice-warning'; break; } ?> status)); ?> payout_status) : ?> payout_status); switch($order->payout_status) { case 'pending': $earnings_class = 'notice-info'; if ($order->available_at) { $earnings_text .= '
Until: ' . date('M j', strtotime($order->available_at)) . ''; } break; case 'available': $earnings_class = 'notice-warning'; break; case 'paid': $earnings_class = 'notice-success'; break; case 'cancelled': $earnings_class = 'notice-error'; break; } ?> creator_earning > 0) : ?>
creator_earning); ?>
status === 'completed') : ?> payout_status === 'pending') : ?>
earning_id, 'wpdd_nonce'); ?>
payout_status !== 'paid') : ?>
id, 'wpdd_nonce'); ?>
id, 'wpdd_nonce'); ?>
status); ?>
update( $wpdb->prefix . 'wpdd_orders', array('status' => 'cancelled'), array('id' => $order_id), array('%s'), array('%d') ); if ($result) { // Revoke download access $wpdb->delete( $wpdb->prefix . 'wpdd_download_links', array('order_id' => $order_id), array('%d') ); // Cancel associated earnings $earning_id = $wpdb->get_var($wpdb->prepare( "SELECT id FROM {$wpdb->prefix}wpdd_creator_earnings WHERE order_id = %d", $order_id )); if ($earning_id) { WPDD_Earnings_Processor::cancel_earning($earning_id, 'Order cancelled by admin'); } } return $result > 0; } private static function refund_order($order_id) { global $wpdb; // Update order status $result = $wpdb->update( $wpdb->prefix . 'wpdd_orders', array('status' => 'refunded'), array('id' => $order_id), array('%s'), array('%d') ); if ($result) { // Revoke download access $wpdb->delete( $wpdb->prefix . 'wpdd_download_links', array('order_id' => $order_id), array('%d') ); // Cancel associated earnings $earning_id = $wpdb->get_var($wpdb->prepare( "SELECT id FROM {$wpdb->prefix}wpdd_creator_earnings WHERE order_id = %d", $order_id )); if ($earning_id) { WPDD_Earnings_Processor::cancel_earning($earning_id, 'Order refunded by admin'); } } return $result > 0; } }