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.
This commit is contained in:
@@ -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 = '<table class="order-details" style="width: 100%; border-collapse: collapse;">';
|
||||
$items_html .= '<thead><tr>';
|
||||
$items_html .= '<th style="text-align: left; padding: 12px 0; border-bottom: 1px solid #e5e5e5;">Product</th>';
|
||||
$items_html .= '<th style="text-align: center; padding: 12px 0; border-bottom: 1px solid #e5e5e5;">Qty</th>';
|
||||
$items_html .= '<th style="text-align: right; padding: 12px 0; border-bottom: 1px solid #e5e5e5;">Price</th>';
|
||||
$items_html .= '</tr></thead><tbody>';
|
||||
|
||||
foreach ($data->get_items() as $item) {
|
||||
$product = $item->get_product();
|
||||
$items_html .= '<tr>';
|
||||
$items_html .= sprintf(
|
||||
'<tr><td>%s × %d</td><td>%s</td></tr>',
|
||||
$item->get_name(),
|
||||
$item->get_quantity(),
|
||||
'<td style="padding: 16px 0; border-bottom: 1px solid #e5e5e5;">%s</td>',
|
||||
$item->get_name()
|
||||
);
|
||||
$items_html .= sprintf(
|
||||
'<td style="text-align: center; padding: 16px 0; border-bottom: 1px solid #e5e5e5;">%d</td>',
|
||||
$item->get_quantity()
|
||||
);
|
||||
$items_html .= sprintf(
|
||||
'<td style="text-align: right; padding: 16px 0; border-bottom: 1px solid #e5e5e5; font-weight: 600;">%s</td>',
|
||||
wc_price($item->get_total())
|
||||
);
|
||||
$items_html .= '</tr>';
|
||||
}
|
||||
|
||||
$items_html .= '</tbody></table>';
|
||||
|
||||
// Both naming conventions for compatibility
|
||||
$variables['order_items'] = $items_html;
|
||||
$variables['order_items_table'] = $items_html;
|
||||
}
|
||||
|
||||
// Product variables
|
||||
|
||||
Reference in New Issue
Block a user