/* Plugin Name: Subscription Total Calculator V2 */ function calculate_last_12_months_payments() { // Get user ID $user_id = get_current_user_id(); // Get all completed orders for the user in the last 364 days $last_364_days_orders = wc_get_orders(array( 'limit' => -1, 'status' => 'completed', 'customer_id' => $user_id, 'date_query' => array( array( 'after' => date('Y-m-d', strtotime('-364 days')), ), ), )); $total_payment = 0; // Loop through the orders and calculate the total payment foreach ($last_364_days_orders as $order) { $total_payment += $order->get_total(); } // Round total payment to 2 decimal places $total_payment = round($total_payment, 2); // Output the total payment with centered alignment $output = '
You\'ve Got: ' . wc_price($total_payment) . ' Credit
';
// Calculate the remaining value after subtracting total payments from $999
$remaining_value = round(999 - $total_payment, 2);
$output .= 'LifeTime Price (credit applied): ' . wc_price($remaining_value) . '