From 88de190df426bcd8d8e58fb091f5ed251ed8f300 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 18 Nov 2025 22:03:51 +0700 Subject: [PATCH] fix: Add all missing email template variables Fixed missing variables: completion_date, order_items_table, payment_date, transaction_id, tracking_number, review_url, shop_url, and more. Added proper HTML table for order items with styling. All template variables now properly replaced in emails. --- includes/Core/Notifications/EmailRenderer.php | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/includes/Core/Notifications/EmailRenderer.php b/includes/Core/Notifications/EmailRenderer.php index 0e69fa0..1f31707 100644 --- a/includes/Core/Notifications/EmailRenderer.php +++ b/includes/Core/Notifications/EmailRenderer.php @@ -152,6 +152,20 @@ class EmailRenderer { // Calculate estimated delivery (3-5 business days from now) $estimated_delivery = date('F j', strtotime('+3 days')) . '-' . date('j', strtotime('+5 days')); + // Completion date (for completed orders) + $completion_date = ''; + if ($data->get_date_completed()) { + $completion_date = $data->get_date_completed()->date('F j, Y'); + } else { + $completion_date = date('F j, Y'); // Fallback to today + } + + // Payment date + $payment_date = ''; + if ($data->get_date_paid()) { + $payment_date = $data->get_date_paid()->date('F j, Y'); + } + $variables = array_merge($variables, [ 'order_number' => $data->get_order_number(), 'order_id' => $data->get_id(), @@ -164,8 +178,12 @@ class EmailRenderer { 'order_status' => wc_get_order_status_name($data->get_status()), 'order_url' => $data->get_view_order_url(), 'payment_method' => $data->get_payment_method_title(), + 'payment_status' => $data->get_status(), + 'payment_date' => $payment_date, + 'transaction_id' => $data->get_transaction_id() ?: 'N/A', 'shipping_method' => $data->get_shipping_method(), 'estimated_delivery' => $estimated_delivery, + 'completion_date' => $completion_date, 'customer_name' => $data->get_formatted_billing_full_name(), 'customer_first_name' => $data->get_billing_first_name(), 'customer_last_name' => $data->get_billing_last_name(), @@ -173,20 +191,48 @@ class EmailRenderer { 'customer_phone' => $data->get_billing_phone(), 'billing_address' => $data->get_formatted_billing_address(), 'shipping_address' => $data->get_formatted_shipping_address(), + // URLs + 'review_url' => $data->get_view_order_url(), // Can be customized later + 'shop_url' => get_permalink(wc_get_page_id('shop')), + 'my_account_url' => get_permalink(wc_get_page_id('myaccount')), + 'payment_retry_url' => $data->get_checkout_payment_url(), + // Tracking (if available from meta) + 'tracking_number' => $data->get_meta('_tracking_number') ?: 'N/A', + 'tracking_url' => $data->get_meta('_tracking_url') ?: '#', + 'shipping_carrier' => $data->get_meta('_shipping_carrier') ?: 'Standard Shipping', ]); - // Order items - $items_html = ''; + // Order items table + $items_html = ''; + $items_html .= ''; + $items_html .= ''; + $items_html .= ''; + $items_html .= ''; + $items_html .= ''; + foreach ($data->get_items() as $item) { $product = $item->get_product(); + $items_html .= ''; $items_html .= sprintf( - '', - $item->get_name(), - $item->get_quantity(), + '', + $item->get_name() + ); + $items_html .= sprintf( + '', + $item->get_quantity() + ); + $items_html .= sprintf( + '', wc_price($item->get_total()) ); + $items_html .= ''; } + + $items_html .= '
ProductQtyPrice
%s × %d%s
%s%d%s
'; + + // Both naming conventions for compatibility $variables['order_items'] = $items_html; + $variables['order_items_table'] = $items_html; } // Product variables