feat: Complete Default Email Templates for All Events! 📧
## Task 7 Complete: Default Email Content ✅ ### New File Created: **`DefaultEmailTemplates.php`** - Comprehensive default templates for all 9 events - Separate templates for staff vs customer recipients - Professional, well-structured HTML with card blocks - All use modern card-based email builder syntax ### Email Templates Included: **Order Events:** 1. **Order Placed** (Staff) - Hero card with order notification - Order details, customer info, items list - View order button 2. **Order Processing** (Customer) - Success card confirmation - Order summary with status - What's next information - Track order button 3. **Order Completed** (Customer) - Success card celebration - Order details with completion date - Thank you message - View order + Continue shopping buttons 4. **Order Cancelled** (Staff) - Warning card notification - Order and customer details - View order button 5. **Order Refunded** (Customer) - Info card with refund notification - Refund details and amount - Timeline expectations - View order button **Product Events:** 6. **Low Stock Alert** (Staff) - Warning card - Product details with stock levels - Action required message - View product button 7. **Out of Stock Alert** (Staff) - Warning card - Product details - Immediate action required - Manage product button **Customer Events:** 8. **New Customer** (Customer) - Hero welcome card - Account details - Feature list (order history, tracking, etc.) - My Account + Start Shopping buttons 9. **Customer Note** (Customer) - Info card - Order details - Note content display - View order button ### Integration: - Updated `TemplateProvider.php` to use DefaultEmailTemplates - Automatic template generation for all events - Push notification templates also complete - Proper variable mapping per event type ### Features: - Card-based modern design - Hero/Success/Warning/Info card types - Multiple buttons with solid/outline styles - Proper variable placeholders - Professional copy for all scenarios - Consistent branding throughout All 7 tasks now complete! 🎉
This commit is contained in:
@@ -128,155 +128,121 @@ class TemplateProvider {
|
||||
* @return array
|
||||
*/
|
||||
public static function get_default_templates() {
|
||||
// Try to load WooCommerce email templates
|
||||
$wc_new_order = self::get_wc_email_template('WC_Email_New_Order');
|
||||
$wc_processing = self::get_wc_email_template('WC_Email_Customer_Processing_Order');
|
||||
$wc_completed = self::get_wc_email_template('WC_Email_Customer_Completed_Order');
|
||||
$wc_refunded = self::get_wc_email_template('WC_Email_Customer_Refunded_Order');
|
||||
$wc_cancelled = self::get_wc_email_template('WC_Email_Cancelled_Order');
|
||||
$wc_new_account = self::get_wc_email_template('WC_Email_Customer_New_Account');
|
||||
$wc_customer_note = self::get_wc_email_template('WC_Email_Customer_Note');
|
||||
$templates = [];
|
||||
|
||||
return [
|
||||
// Email templates - Staff
|
||||
'order_placed_email' => [
|
||||
'event_id' => 'order_placed',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_new_order['subject'] ?? __('New Order #{order_number}', 'woonoow'),
|
||||
'body' => __('[card]
|
||||
<h1>New Order Received</h1>
|
||||
<p>Hi Admin,</p>
|
||||
<p>You have received a new order from <strong>{customer_name}</strong>.</p>
|
||||
<div class="info-box">
|
||||
<p style="margin: 0;"><strong>Order #{order_number}</strong></p>
|
||||
<p style="margin: 0;">Total: {order_total}</p>
|
||||
</div>
|
||||
[/card]
|
||||
|
||||
[card]
|
||||
<h2>Customer Details</h2>
|
||||
<p><strong>Name:</strong> {customer_name}<br>
|
||||
<strong>Email:</strong> {customer_email}<br>
|
||||
<strong>Phone:</strong> {customer_phone}</p>
|
||||
[/card]
|
||||
|
||||
[button link="{order_url}" style="solid"]View Order Details[/button]', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_New_Order',
|
||||
],
|
||||
'order_processing_email' => [
|
||||
'event_id' => 'order_processing',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_processing['subject'] ?? __('Your order #{order_number} is being processed', 'woonoow'),
|
||||
'body' => __('[card type="success"]
|
||||
<h1>✅ Order Confirmed!</h1>
|
||||
<p>Hi {customer_name},</p>
|
||||
<p>Thank you for your order! We\'re now processing it and will notify you once it ships.</p>
|
||||
[/card]
|
||||
|
||||
[card]
|
||||
<h2>Order Summary</h2>
|
||||
<div class="info-box">
|
||||
<p style="margin: 0;"><strong>Order #{order_number}</strong></p>
|
||||
<p style="margin: 0;">Total: {order_total}</p>
|
||||
<p style="margin: 0;">Payment: {payment_method}</p>
|
||||
</div>
|
||||
{order_items_table}
|
||||
[/card]
|
||||
|
||||
[button link="{order_url}" style="solid"]Track Your Order[/button]
|
||||
|
||||
[card]
|
||||
<p style="text-align: center; font-size: 14px; color: #888;">Questions? Reply to this email or contact us.</p>
|
||||
[/card]', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_Customer_Processing_Order',
|
||||
],
|
||||
'order_completed_email' => [
|
||||
'event_id' => 'order_completed',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_completed['subject'] ?? __('Your order #{order_number} is complete', 'woonoow'),
|
||||
'body' => __("Hi {customer_name},\n\nYour order has been completed and shipped!\n\nOrder Number: {order_number}\nOrder Total: {order_total}\nTracking Number: {tracking_number}\n\nThank you for shopping with us!\n\nBest regards,\n{store_name}", 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_Customer_Completed_Order',
|
||||
],
|
||||
'order_cancelled_email' => [
|
||||
'event_id' => 'order_cancelled',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_cancelled['subject'] ?? __('Order #{order_number} has been cancelled', 'woonoow'),
|
||||
'body' => __("Hi Admin,\n\nOrder #{order_number} has been cancelled.\n\nOrder Number: {order_number}\nOrder Total: {order_total}\nCustomer: {customer_name}\n\nView order: {order_url}", 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_Cancelled_Order',
|
||||
],
|
||||
'order_refunded_email' => [
|
||||
'event_id' => 'order_refunded',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_refunded['subject'] ?? __('Your order #{order_number} has been refunded', 'woonoow'),
|
||||
'body' => __("Hi {customer_name},\n\nYour order has been refunded.\n\nOrder Number: {order_number}\nRefund Amount: {refund_amount}\n\nThe refund will be processed within 5-7 business days.\n\nBest regards,\n{store_name}", 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_Customer_Refunded_Order',
|
||||
],
|
||||
'low_stock_email' => [
|
||||
'event_id' => 'low_stock',
|
||||
'channel_id' => 'email',
|
||||
'subject' => __('Low Stock Alert: {product_name}', 'woonoow'),
|
||||
'body' => __("Hi Admin,\n\nThe following product is running low on stock:\n\nProduct: {product_name}\nSKU: {product_sku}\nCurrent Stock: {stock_quantity}\n\nPlease restock soon.\n\nView product: {product_url}", 'woonoow'),
|
||||
'variables' => self::get_product_variables(),
|
||||
],
|
||||
'out_of_stock_email' => [
|
||||
'event_id' => 'out_of_stock',
|
||||
'channel_id' => 'email',
|
||||
'subject' => __('Out of Stock Alert: {product_name}', 'woonoow'),
|
||||
'body' => __("Hi Admin,\n\nThe following product is now out of stock:\n\nProduct: {product_name}\nSKU: {product_sku}\n\nPlease restock immediately.\n\nView product: {product_url}", 'woonoow'),
|
||||
'variables' => self::get_product_variables(),
|
||||
],
|
||||
'new_customer_email' => [
|
||||
'event_id' => 'new_customer',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_new_account['subject'] ?? __('Welcome to {store_name}!', 'woonoow'),
|
||||
'body' => __("Hi {customer_name},\n\nWelcome to {store_name}!\n\nYour account has been created successfully.\n\nEmail: {customer_email}\n\nYou can now browse our products and place orders.\n\nVisit our store: {store_url}\n\nBest regards,\n{store_name}", 'woonoow'),
|
||||
'variables' => self::get_customer_variables(),
|
||||
'wc_email_id' => 'WC_Email_Customer_New_Account',
|
||||
],
|
||||
'customer_note_email' => [
|
||||
'event_id' => 'customer_note',
|
||||
'channel_id' => 'email',
|
||||
'subject' => $wc_customer_note['subject'] ?? __('Note added to your order #{order_number}', 'woonoow'),
|
||||
'body' => __("Hi {customer_name},\n\nA note has been added to your order:\n\nOrder Number: {order_number}\nNote: {note_content}\n\nView order: {order_url}\n\nBest regards,\n{store_name}", 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
'wc_email_id' => 'WC_Email_Customer_Note',
|
||||
],
|
||||
|
||||
// Push notification templates
|
||||
'order_placed_push' => [
|
||||
'event_id' => 'order_placed',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('New Order #{order_number}', 'woonoow'),
|
||||
'body' => __('New order from {customer_name} - {order_total}', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
],
|
||||
'order_processing_push' => [
|
||||
'event_id' => 'order_processing',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Processing', 'woonoow'),
|
||||
'body' => __('Your order #{order_number} is being processed', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
],
|
||||
'order_completed_push' => [
|
||||
'event_id' => 'order_completed',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Completed', 'woonoow'),
|
||||
'body' => __('Your order #{order_number} has been completed!', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
],
|
||||
'low_stock_push' => [
|
||||
'event_id' => 'low_stock',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Low Stock Alert', 'woonoow'),
|
||||
'body' => __('{product_name} is running low on stock', 'woonoow'),
|
||||
'variables' => self::get_product_variables(),
|
||||
],
|
||||
// Define all events with their recipient types
|
||||
$events = [
|
||||
'order_placed' => 'staff',
|
||||
'order_processing' => 'customer',
|
||||
'order_completed' => 'customer',
|
||||
'order_cancelled' => 'staff',
|
||||
'order_refunded' => 'customer',
|
||||
'low_stock' => 'staff',
|
||||
'out_of_stock' => 'staff',
|
||||
'new_customer' => 'customer',
|
||||
'customer_note' => 'customer',
|
||||
];
|
||||
|
||||
// Generate email templates from DefaultEmailTemplates
|
||||
foreach ($events as $event_id => $recipient_type) {
|
||||
$default = DefaultEmailTemplates::get_template($event_id, $recipient_type);
|
||||
|
||||
$templates["{$event_id}_email"] = [
|
||||
'event_id' => $event_id,
|
||||
'channel_id' => 'email',
|
||||
'subject' => $default['subject'],
|
||||
'body' => $default['body'],
|
||||
'variables' => self::get_variables_for_event($event_id),
|
||||
];
|
||||
}
|
||||
|
||||
// Add push notification templates
|
||||
$templates['order_placed_push'] = [
|
||||
'event_id' => 'order_placed',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('New Order #{order_number}', 'woonoow'),
|
||||
'body' => __('New order from {customer_name} - {order_total}', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
$templates['order_processing_push'] = [
|
||||
'event_id' => 'order_processing',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Processing', 'woonoow'),
|
||||
'body' => __('Your order #{order_number} is being processed', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
$templates['order_completed_push'] = [
|
||||
'event_id' => 'order_completed',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Completed', 'woonoow'),
|
||||
'body' => __('Your order #{order_number} has been completed!', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
$templates['order_cancelled_push'] = [
|
||||
'event_id' => 'order_cancelled',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Cancelled', 'woonoow'),
|
||||
'body' => __('Order #{order_number} has been cancelled', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
$templates['order_refunded_push'] = [
|
||||
'event_id' => 'order_refunded',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Refunded', 'woonoow'),
|
||||
'body' => __('Your order #{order_number} has been refunded', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
$templates['low_stock_push'] = [
|
||||
'event_id' => 'low_stock',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Low Stock Alert', 'woonoow'),
|
||||
'body' => __('{product_name} is running low on stock', 'woonoow'),
|
||||
'variables' => self::get_product_variables(),
|
||||
];
|
||||
$templates['out_of_stock_push'] = [
|
||||
'event_id' => 'out_of_stock',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Out of Stock Alert', 'woonoow'),
|
||||
'body' => __('{product_name} is now out of stock', 'woonoow'),
|
||||
'variables' => self::get_product_variables(),
|
||||
];
|
||||
$templates['new_customer_push'] = [
|
||||
'event_id' => 'new_customer',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Welcome!', 'woonoow'),
|
||||
'body' => __('Welcome to {store_name}, {customer_name}!', 'woonoow'),
|
||||
'variables' => self::get_customer_variables(),
|
||||
];
|
||||
$templates['customer_note_push'] = [
|
||||
'event_id' => 'customer_note',
|
||||
'channel_id' => 'push',
|
||||
'subject' => __('Order Note Added', 'woonoow'),
|
||||
'body' => __('A note has been added to order #{order_number}', 'woonoow'),
|
||||
'variables' => self::get_order_variables(),
|
||||
];
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variables for a specific event
|
||||
*
|
||||
* @param string $event_id Event ID
|
||||
* @return array
|
||||
*/
|
||||
private static function get_variables_for_event($event_id) {
|
||||
// Product events
|
||||
if (in_array($event_id, ['low_stock', 'out_of_stock'])) {
|
||||
return self::get_product_variables();
|
||||
}
|
||||
|
||||
// Customer events (but not order-related)
|
||||
if ($event_id === 'new_customer') {
|
||||
return self::get_customer_variables();
|
||||
}
|
||||
|
||||
// All other events are order-related
|
||||
return self::get_order_variables();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user