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:
dwindown
2025-11-13 15:27:16 +07:00
parent b6c2b077ee
commit a3aab7f4a0
2 changed files with 393 additions and 147 deletions

View File

@@ -0,0 +1,280 @@
<?php
/**
* Default Email Templates
*
* Provides default email content for all notification events
*
* @package WooNooW
*/
namespace WooNooW\Core\Notifications;
class DefaultEmailTemplates {
/**
* Get default template for an event and recipient type
*
* @param string $event_id Event ID
* @param string $recipient_type 'staff' or 'customer'
* @return array ['subject' => string, 'body' => string]
*/
public static function get_template($event_id, $recipient_type) {
$templates = self::get_all_templates();
if (isset($templates[$event_id][$recipient_type])) {
return $templates[$event_id][$recipient_type];
}
// Fallback
return [
'subject' => __('Notification from {store_name}', 'woonoow'),
'body' => '[card type="default"]<p>' . __('You have a new notification.', 'woonoow') . '</p>[/card]',
];
}
/**
* Get all default templates
*
* @return array
*/
private static function get_all_templates() {
return [
// ORDER EVENTS
'order_placed' => [
'staff' => [
'subject' => __('New Order #{order_number} Received', 'woonoow'),
'body' => '[card type="hero"]
<h1>' . __('New Order Received!', 'woonoow') . '</h1>
<p>' . __('You have received a new order from {customer_name}.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Details', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Order Total:', 'woonoow') . '</strong> {order_total}</p>
<p><strong>' . __('Order Date:', 'woonoow') . '</strong> {order_date}</p>
<p><strong>' . __('Payment Method:', 'woonoow') . '</strong> {payment_method}</p>
[/card]
[card type="default"]
<h2>' . __('Customer Details', 'woonoow') . '</h2>
<p><strong>' . __('Name:', 'woonoow') . '</strong> {customer_name}</p>
<p><strong>' . __('Email:', 'woonoow') . '</strong> {customer_email}</p>
<p><strong>' . __('Phone:', 'woonoow') . '</strong> {customer_phone}</p>
[/card]
[card type="default"]
<h2>' . __('Order Items', 'woonoow') . '</h2>
{order_items_list}
[/card]
[button link="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
],
],
'order_processing' => [
'customer' => [
'subject' => __('Your Order #{order_number} is Being Processed', 'woonoow'),
'body' => '[card type="success"]
<h1>' . __('Order Confirmed!', 'woonoow') . '</h1>
<p>' . __('Thank you for your order. We\'re now processing it and will ship it soon.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Summary', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Order Total:', 'woonoow') . '</strong> {order_total}</p>
<p><strong>' . __('Order Status:', 'woonoow') . '</strong> {order_status}</p>
[/card]
[card type="default"]
<h2>' . __('What\'s Next?', 'woonoow') . '</h2>
<p>' . __('We\'ll send you another email once your order has been shipped with tracking information.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Items', 'woonoow') . '</h2>
{order_items_list}
[/card]
[button link="{order_url}" style="solid"]' . __('Track Your Order', 'woonoow') . '[/button]',
],
],
'order_completed' => [
'customer' => [
'subject' => __('Your Order #{order_number} is Complete', 'woonoow'),
'body' => '[card type="success"]
<h1>' . __('Order Completed!', 'woonoow') . '</h1>
<p>' . __('Your order has been completed. We hope you enjoy your purchase!', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Details', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Order Total:', 'woonoow') . '</strong> {order_total}</p>
<p><strong>' . __('Completed Date:', 'woonoow') . '</strong> {order_date}</p>
[/card]
[card type="default"]
<h2>' . __('Thank You!', 'woonoow') . '</h2>
<p>' . __('Thank you for shopping with us. We appreciate your business and hope to serve you again soon.', 'woonoow') . '</p>
<p>' . __('If you have any questions or concerns about your order, please don\'t hesitate to contact us.', 'woonoow') . '</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]
[button link="{store_url}" style="outline"]' . __('Continue Shopping', 'woonoow') . '[/button]',
],
],
'order_cancelled' => [
'staff' => [
'subject' => __('Order #{order_number} Cancelled', 'woonoow'),
'body' => '[card type="warning"]
<h1>' . __('Order Cancelled', 'woonoow') . '</h1>
<p>' . __('Order #{order_number} has been cancelled.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Details', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Order Total:', 'woonoow') . '</strong> {order_total}</p>
<p><strong>' . __('Customer:', 'woonoow') . '</strong> {customer_name}</p>
<p><strong>' . __('Cancelled Date:', 'woonoow') . '</strong> {order_date}</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
],
],
'order_refunded' => [
'customer' => [
'subject' => __('Your Order #{order_number} Has Been Refunded', 'woonoow'),
'body' => '[card type="info"]
<h1>' . __('Refund Processed', 'woonoow') . '</h1>
<p>' . __('Your refund for order #{order_number} has been processed.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Refund Details', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Refund Amount:', 'woonoow') . '</strong> {refund_amount}</p>
<p><strong>' . __('Refund Date:', 'woonoow') . '</strong> {order_date}</p>
[/card]
[card type="default"]
<h2>' . __('What Happens Next?', 'woonoow') . '</h2>
<p>' . __('The refund will be credited back to your original payment method within 5-10 business days.', 'woonoow') . '</p>
<p>' . __('If you have any questions, please contact us.', 'woonoow') . '</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
],
],
// PRODUCT EVENTS
'low_stock' => [
'staff' => [
'subject' => __('Low Stock Alert: {product_name}', 'woonoow'),
'body' => '[card type="warning"]
<h1>' . __('Low Stock Alert', 'woonoow') . '</h1>
<p>' . __('The following product is running low on stock.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Product Details', 'woonoow') . '</h2>
<p><strong>' . __('Product:', 'woonoow') . '</strong> {product_name}</p>
<p><strong>' . __('SKU:', 'woonoow') . '</strong> {product_sku}</p>
<p><strong>' . __('Current Stock:', 'woonoow') . '</strong> {stock_quantity}</p>
<p><strong>' . __('Low Stock Threshold:', 'woonoow') . '</strong> {low_stock_threshold}</p>
[/card]
[card type="default"]
<h2>' . __('Action Required', 'woonoow') . '</h2>
<p>' . __('Please restock this product to avoid running out of inventory.', 'woonoow') . '</p>
[/card]
[button link="{product_url}" style="solid"]' . __('View Product', 'woonoow') . '[/button]',
],
],
'out_of_stock' => [
'staff' => [
'subject' => __('Out of Stock Alert: {product_name}', 'woonoow'),
'body' => '[card type="warning"]
<h1>' . __('Out of Stock Alert', 'woonoow') . '</h1>
<p>' . __('The following product is now out of stock.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Product Details', 'woonoow') . '</h2>
<p><strong>' . __('Product:', 'woonoow') . '</strong> {product_name}</p>
<p><strong>' . __('SKU:', 'woonoow') . '</strong> {product_sku}</p>
<p><strong>' . __('Current Stock:', 'woonoow') . '</strong> 0</p>
[/card]
[card type="default"]
<h2>' . __('Immediate Action Required', 'woonoow') . '</h2>
<p>' . __('This product is no longer available for purchase. Please restock as soon as possible.', 'woonoow') . '</p>
[/card]
[button link="{product_url}" style="solid"]' . __('Manage Product', 'woonoow') . '[/button]',
],
],
// CUSTOMER EVENTS
'new_customer' => [
'customer' => [
'subject' => __('Welcome to {store_name}!', 'woonoow'),
'body' => '[card type="hero"]
<h1>' . __('Welcome!', 'woonoow') . '</h1>
<p>' . __('Thank you for creating an account with {store_name}. We\'re excited to have you!', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Your Account Details', 'woonoow') . '</h2>
<p><strong>' . __('Username:', 'woonoow') . '</strong> {customer_username}</p>
<p><strong>' . __('Email:', 'woonoow') . '</strong> {customer_email}</p>
[/card]
[card type="default"]
<h2>' . __('Get Started', 'woonoow') . '</h2>
<p>' . __('You can now log in to your account to:', 'woonoow') . '</p>
<ul>
<li>' . __('View your order history', 'woonoow') . '</li>
<li>' . __('Track your orders', 'woonoow') . '</li>
<li>' . __('Manage your addresses', 'woonoow') . '</li>
<li>' . __('Update your account details', 'woonoow') . '</li>
</ul>
[/card]
[button link="{account_url}" style="solid"]' . __('Go to My Account', 'woonoow') . '[/button]
[button link="{store_url}" style="outline"]' . __('Start Shopping', 'woonoow') . '[/button]',
],
],
'customer_note' => [
'customer' => [
'subject' => __('Note Added to Your Order #{order_number}', 'woonoow'),
'body' => '[card type="info"]
<h1>' . __('Order Note Added', 'woonoow') . '</h1>
<p>' . __('A note has been added to your order #{order_number}.', 'woonoow') . '</p>
[/card]
[card type="default"]
<h2>' . __('Order Details', 'woonoow') . '</h2>
<p><strong>' . __('Order Number:', 'woonoow') . '</strong> #{order_number}</p>
<p><strong>' . __('Order Status:', 'woonoow') . '</strong> {order_status}</p>
[/card]
[card type="default"]
<h2>' . __('Note from Store', 'woonoow') . '</h2>
<p>{customer_note}</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
],
],
];
}
}

View File

@@ -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();
}
/**