Files
WooNooW/includes/Email/DefaultTemplates_Old.php
dwindown 4471cd600f feat: Complete markdown syntax refinement and variable protection
 New cleaner syntax implemented:
- [card:type] instead of [card type='type']
- [button:style](url)Text[/button] instead of [button url='...' style='...']
- Standard markdown images: ![alt](url)

 Variable protection from markdown parsing:
- Variables with underscores (e.g., {order_items_table}) now protected
- HTML comment placeholders prevent italic/bold parsing
- All variables render correctly in preview

 Button rendering fixes:
- Buttons work in Visual mode inside cards
- Buttons work in Preview mode
- Button clicks prevented in visual editor
- Proper styling for solid and outline buttons

 Backward compatibility:
- Old syntax still supported
- No breaking changes

 Bug fixes:
- Fixed order_item_table → order_items_table naming
- Fixed button regex to match across newlines
- Added button/image parsing to parseMarkdownBasics
- Prevented button clicks on .button and .button-outline classes

📚 Documentation:
- NEW_MARKDOWN_SYNTAX.md - Complete user guide
- MARKDOWN_SYNTAX_AND_VARIABLES.md - Technical analysis
2025-11-15 20:05:50 +07:00

710 lines
21 KiB
PHP

<?php
/**
* Default Email Templates for WooNooW
*
* This file contains default email content templates for all notification types.
* These templates are used when a store is first installed, providing ready-to-use
* email content so merchants can start selling immediately.
*
* Template Structure:
* - Each template is organized by recipient (customer/staff) and event type
* - Templates use [card] shortcode syntax for visual blocks
* - Variables are wrapped in curly braces: {variable_name}
* - Card types: default, success, info, warning, hero
*
* Available Variables by Event:
*
* ORDER EVENTS (order_placed, order_confirmed, order_shipped, order_completed, order_cancelled):
* - {customer_name} - Customer's full name
* - {order_number} - Order number/ID
* - {order_date} - Order creation date
* - {order_total} - Total order amount
* - {order_url} - Link to view order details
* - {order_items} - List of ordered items
* - {payment_method} - Payment method used
* - {shipping_address} - Full shipping address
* - {billing_address} - Full billing address
* - {tracking_number} - Shipping tracking number (if available)
* - {tracking_url} - Tracking URL (if available)
*
* PAYMENT EVENTS (payment_received, payment_failed):
* - All order variables above, plus:
* - {payment_status} - Current payment status
* - {payment_date} - Payment date/time
* - {transaction_id} - Payment transaction ID
*
* CUSTOMER EVENTS (customer_registered, customer_vip_upgraded):
* - {customer_name} - Customer's full name
* - {customer_email} - Customer's email
* - {account_url} - Link to customer account
* - {vip_benefits} - List of VIP benefits (for vip_upgraded)
*
* COMMON VARIABLES (available in all templates):
* - {site_name} - Store name
* - {site_url} - Store URL
* - {support_email} - Support email address
* - {current_year} - Current year (for copyright)
*
* Card Syntax Examples:
*
* [card]
* <h2>Simple Card</h2>
* <p>Default card with white background</p>
* [/card]
*
* [card type="success"]
* <h2>Success Card</h2>
* <p>Green-themed card for positive messages</p>
* [/card]
*
* [card type="hero"]
* <h2>Hero Card</h2>
* <p>Large header card with gradient background</p>
* [/card]
*
* Button Syntax:
* <p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
* <p style="text-align: center;"><a href="{order_url}" class="button-outline">View Order</a></p>
*
* @package WooNooW
* @subpackage Email
*/
namespace WooNooW\Email;
class DefaultTemplates {
/**
* Get all default templates organized by recipient and event
*
* @return array Associative array of templates
*/
public static function get_all_templates() {
return [
'customer' => [
'order_placed' => self::customer_order_placed(),
'order_confirmed' => self::customer_order_confirmed(),
'order_shipped' => self::customer_order_shipped(),
'order_completed' => self::customer_order_completed(),
'order_cancelled' => self::customer_order_cancelled(),
'payment_received' => self::customer_payment_received(),
'payment_failed' => self::customer_payment_failed(),
'customer_registered' => self::customer_registered(),
'customer_vip_upgraded' => self::customer_vip_upgraded(),
],
'staff' => [
'order_placed' => self::staff_order_placed(),
'order_confirmed' => self::staff_order_confirmed(),
'order_shipped' => self::staff_order_shipped(),
'order_completed' => self::staff_order_completed(),
'order_cancelled' => self::staff_order_cancelled(),
'payment_received' => self::staff_payment_received(),
'payment_failed' => self::staff_payment_failed(),
],
];
}
/**
* Get default subject for a specific template
*
* @param string $recipient 'customer' or 'staff'
* @param string $event Event type
* @return string Default subject line
*/
public static function get_default_subject($recipient, $event) {
$subjects = [
'customer' => [
'order_placed' => 'Order Received - #{order_number}',
'order_confirmed' => 'Order Confirmed - #{order_number}',
'order_shipped' => 'Your Order Has Shipped - #{order_number}',
'order_completed' => 'Order Delivered - #{order_number}',
'order_cancelled' => 'Order Cancelled - #{order_number}',
'payment_received' => 'Payment Received - #{order_number}',
'payment_failed' => 'Payment Failed - #{order_number}',
'customer_registered' => 'Welcome to {site_name}!',
'customer_vip_upgraded' => 'You\'re Now a VIP Member!',
],
'staff' => [
'order_placed' => '[New Order] #{order_number} from {customer_name}',
'order_confirmed' => '[Order Confirmed] #{order_number}',
'order_shipped' => '[Order Shipped] #{order_number}',
'order_completed' => '[Order Completed] #{order_number}',
'order_cancelled' => '[Order Cancelled] #{order_number}',
'payment_received' => '[Payment Received] #{order_number}',
'payment_failed' => '[Payment Failed] #{order_number}',
],
];
return $subjects[$recipient][$event] ?? '';
}
// ============================================================================
// CUSTOMER TEMPLATES
// ============================================================================
/**
* Customer: Order Placed
* Sent immediately when customer places an order
*/
private static function customer_order_placed() {
return '[card type="hero"]
<h1>Order Received!</h1>
<p>Thank you for your order, {customer_name}. We\'ve received your order and will process it shortly.</p>
[/card]
[card]
<h2>Order Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Order Date:</strong> {order_date}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Payment Method:</strong> {payment_method}</p>
[/card]
[card]
<h3>Items Ordered</h3>
{order_items}
[/card]
[card type="info"]
<h3>Shipping Address</h3>
{shipping_address}
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order Details</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Need help? Contact us at {support_email}<br>
© {current_year} {site_name}. All rights reserved.
</p>
[/card]';
}
/**
* Customer: Order Confirmed
* Sent when staff confirms the order
*/
private static function customer_order_confirmed() {
return '[card type="success"]
<h1>Order Confirmed!</h1>
<p>Great news, {customer_name}! Your order #{order_number} has been confirmed and is being prepared for shipment.</p>
[/card]
[card]
<h2>Order Summary</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Estimated Delivery:</strong> 3-5 business days</p>
[/card]
[card]
<h3>What\'s Next?</h3>
<p>✓ Your order is being carefully prepared</p>
<p>✓ You\'ll receive a shipping notification with tracking info</p>
<p>✓ Track your order anytime using the link below</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">Track Your Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Questions? We\'re here to help at {support_email}<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Order Shipped
* Sent when order is marked as shipped
*/
private static function customer_order_shipped() {
return '[card type="hero"]
<h1>Your Order is On Its Way!</h1>
<p>Good news, {customer_name}! Your order #{order_number} has been shipped and is heading your way.</p>
[/card]
[card type="info"]
<h2>Tracking Information</h2>
<p><strong>Tracking Number:</strong> {tracking_number}</p>
<p><strong>Carrier:</strong> Standard Shipping</p>
<p><strong>Estimated Delivery:</strong> 2-3 business days</p>
[/card]
[card]
<h3>Shipping To:</h3>
{shipping_address}
[/card]
<p style="text-align: center;"><a href="{tracking_url}" class="button">Track Your Package</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Need assistance? Contact {support_email}<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Order Completed
* Sent when order is marked as completed/delivered
*/
private static function customer_order_completed() {
return '[card type="success"]
<h1>Order Delivered!</h1>
<p>Your order #{order_number} has been successfully delivered. We hope you love your purchase!</p>
[/card]
[card]
<h2>How Was Your Experience?</h2>
<p>We\'d love to hear your feedback! Your review helps us improve and helps other customers make informed decisions.</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">Leave a Review</a></p>
[card type="info"]
<h3>Need Support?</h3>
<p>If you have any questions or concerns about your order, our support team is ready to help.</p>
<p style="text-align: center;"><a href="mailto:{support_email}" class="button-outline">Contact Support</a></p>
[/card]
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Thank you for shopping with us!<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Order Cancelled
* Sent when order is cancelled
*/
private static function customer_order_cancelled() {
return '[card type="warning"]
<h1>Order Cancelled</h1>
<p>Your order #{order_number} has been cancelled as requested.</p>
[/card]
[card]
<h2>Cancellation Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Cancellation Date:</strong> {order_date}</p>
[/card]
[card type="info"]
<h3>Refund Information</h3>
<p>If you\'ve already made a payment, a refund will be processed to your original payment method within 5-7 business days.</p>
[/card]
[card]
<h3>Changed Your Mind?</h3>
<p>You can always place a new order anytime. We\'re here whenever you need us!</p>
<p style="text-align: center;"><a href="{site_url}" class="button">Continue Shopping</a></p>
[/card]
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Questions? Contact {support_email}<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Payment Received
* Sent when payment is successfully processed
*/
private static function customer_payment_received() {
return '[card type="success"]
<h1>Payment Received!</h1>
<p>Thank you, {customer_name}! We\'ve received your payment for order #{order_number}.</p>
[/card]
[card]
<h2>Payment Details</h2>
<p><strong>Amount Paid:</strong> {order_total}</p>
<p><strong>Payment Method:</strong> {payment_method}</p>
<p><strong>Transaction ID:</strong> {transaction_id}</p>
<p><strong>Payment Date:</strong> {payment_date}</p>
[/card]
[card type="info"]
<h3>What\'s Next?</h3>
<p>Your order is now being processed and will be shipped soon. You\'ll receive a shipping notification with tracking information.</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Keep this email for your records<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Payment Failed
* Sent when payment processing fails
*/
private static function customer_payment_failed() {
return '[card type="warning"]
<h1>Payment Issue</h1>
<p>We were unable to process your payment for order #{order_number}.</p>
[/card]
[card]
<h2>What Happened?</h2>
<p>Your payment could not be completed. This can happen for several reasons:</p>
<p>• Insufficient funds</p>
<p>• Incorrect card details</p>
<p>• Card expired or blocked</p>
<p>• Bank security check</p>
[/card]
[card type="info"]
<h3>How to Fix This</h3>
<p>Please update your payment information and try again. Your order is still reserved for you.</p>
<p style="text-align: center;"><a href="{order_url}" class="button">Update Payment Method</a></p>
[/card]
[card]
<h3>Need Help?</h3>
<p>If you continue to experience issues, please contact your bank or reach out to our support team.</p>
<p>Email: {support_email}</p>
[/card]
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: Account Registered
* Sent when customer creates an account
*/
private static function customer_registered() {
return '[card type="hero"]
<h1>Welcome to {site_name}!</h1>
<p>Hi {customer_name}, we\'re thrilled to have you join our community!</p>
[/card]
[card]
<h2>Your Account is Ready</h2>
<p>You can now enjoy all the benefits of being a registered member:</p>
<p>✓ Faster checkout process</p>
<p>✓ Order history and tracking</p>
<p>✓ Exclusive member offers</p>
<p>✓ Wishlist and favorites</p>
<p>✓ Easy returns and exchanges</p>
[/card]
<p style="text-align: center;"><a href="{account_url}" class="button">Go to My Account</a></p>
[card type="success"]
<h3>Start Shopping!</h3>
<p>Browse our latest products and discover amazing deals just for you.</p>
<p style="text-align: center;"><a href="{site_url}" class="button-outline">Start Shopping</a></p>
[/card]
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Need help? We\'re here for you at {support_email}<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Customer: VIP Upgraded
* Sent when customer is upgraded to VIP status
*/
private static function customer_vip_upgraded() {
return '[card type="hero"]
<h1>🎉 You\'re Now a VIP!</h1>
<p>Congratulations, {customer_name}! You\'ve been upgraded to VIP status.</p>
[/card]
[card type="success"]
<h2>Your VIP Benefits</h2>
{vip_benefits}
[/card]
[card]
<h3>How to Use Your Benefits</h3>
<p>Your VIP perks are automatically applied to your account. Simply shop as usual and enjoy your exclusive benefits!</p>
[/card]
<p style="text-align: center;"><a href="{account_url}" class="button">View My VIP Dashboard</a></p>
[card type="info"]
<h3>Thank You for Your Loyalty</h3>
<p>We truly appreciate your continued support. As a VIP member, you\'re part of our most valued customer group.</p>
[/card]
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Questions about your VIP status? Contact {support_email}<br>
© {current_year} {site_name}
</p>
[/card]';
}
// ============================================================================
// STAFF TEMPLATES
// ============================================================================
/**
* Staff: New Order Placed
* Notifies staff when a new order is received
*/
private static function staff_order_placed() {
return '[card type="info"]
<h1>New Order Received</h1>
<p>A new order has been placed by {customer_name}.</p>
[/card]
[card]
<h2>Order Information</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Order Date:</strong> {order_date}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Payment Method:</strong> {payment_method}</p>
<p><strong>Payment Status:</strong> {payment_status}</p>
[/card]
[card]
<h3>Items Ordered</h3>
{order_items}
[/card]
[card]
<h3>Shipping Address</h3>
{shipping_address}
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">Process Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
WooNooW Order Notification<br>
© {current_year} {site_name}
</p>
[/card]';
}
/**
* Staff: Order Confirmed
* Notifies staff when order is confirmed
*/
private static function staff_order_confirmed() {
return '[card type="success"]
<h1>Order Confirmed</h1>
<p>Order #{order_number} has been confirmed and is ready for processing.</p>
[/card]
[card]
<h2>Order Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Confirmed Date:</strong> {order_date}</p>
[/card]
[card type="info"]
<h3>Next Steps</h3>
<p>• Prepare items for shipment</p>
<p>• Update inventory</p>
<p>• Generate shipping label</p>
<p>• Mark as shipped when ready</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
WooNooW Order Notification
</p>
[/card]';
}
/**
* Staff: Order Shipped
* Notifies staff when order is shipped
*/
private static function staff_order_shipped() {
return '[card type="success"]
<h1>Order Shipped</h1>
<p>Order #{order_number} has been marked as shipped.</p>
[/card]
[card]
<h2>Shipment Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Tracking Number:</strong> {tracking_number}</p>
<p><strong>Shipped Date:</strong> {order_date}</p>
[/card]
[card]
<h3>Shipping Address</h3>
{shipping_address}
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Customer has been notified via email
</p>
[/card]';
}
/**
* Staff: Order Completed
* Notifies staff when order is completed
*/
private static function staff_order_completed() {
return '[card type="success"]
<h1>Order Completed</h1>
<p>Order #{order_number} has been marked as completed.</p>
[/card]
[card]
<h2>Order Summary</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Completion Date:</strong> {order_date}</p>
[/card]
[card type="info"]
<h3>Order Lifecycle Complete</h3>
<p>✓ Order placed</p>
<p>✓ Payment received</p>
<p>✓ Order shipped</p>
<p>✓ Delivered to customer</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Customer has been notified
</p>
[/card]';
}
/**
* Staff: Order Cancelled
* Notifies staff when order is cancelled
*/
private static function staff_order_cancelled() {
return '[card type="warning"]
<h1>Order Cancelled</h1>
<p>Order #{order_number} has been cancelled.</p>
[/card]
[card]
<h2>Cancellation Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Cancellation Date:</strong> {order_date}</p>
[/card]
[card type="info"]
<h3>Action Required</h3>
<p>• Process refund if payment was received</p>
<p>• Update inventory</p>
<p>• Notify warehouse if order was being prepared</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Customer has been notified
</p>
[/card]';
}
/**
* Staff: Payment Received
* Notifies staff when payment is received
*/
private static function staff_payment_received() {
return '[card type="success"]
<h1>Payment Received</h1>
<p>Payment has been received for order #{order_number}.</p>
[/card]
[card]
<h2>Payment Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Amount:</strong> {order_total}</p>
<p><strong>Payment Method:</strong> {payment_method}</p>
<p><strong>Transaction ID:</strong> {transaction_id}</p>
<p><strong>Payment Date:</strong> {payment_date}</p>
[/card]
[card type="info"]
<h3>Next Steps</h3>
<p>• Confirm the order</p>
<p>• Begin order processing</p>
<p>• Prepare for shipment</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">Process Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
Customer has been notified
</p>
[/card]';
}
/**
* Staff: Payment Failed
* Notifies staff when payment fails
*/
private static function staff_payment_failed() {
return '[card type="warning"]
<h1>Payment Failed</h1>
<p>Payment processing failed for order #{order_number}.</p>
[/card]
[card]
<h2>Order Details</h2>
<p><strong>Order Number:</strong> #{order_number}</p>
<p><strong>Customer:</strong> {customer_name}</p>
<p><strong>Order Total:</strong> {order_total}</p>
<p><strong>Payment Method:</strong> {payment_method}</p>
<p><strong>Failed Date:</strong> {payment_date}</p>
[/card]
[card type="info"]
<h3>Action Required</h3>
<p>• Customer has been notified</p>
<p>• Order is on hold pending payment</p>
<p>• Follow up with customer if needed</p>
<p>• Consider cancelling if payment not received within 24 hours</p>
[/card]
<p style="text-align: center;"><a href="{order_url}" class="button">View Order</a></p>
[card]
<p style="text-align: center; color: #666; font-size: 14px;">
WooNooW Payment Notification
</p>
[/card]';
}
}