✅ New cleaner syntax implemented: - [card:type] instead of [card type='type'] - [button:style](url)Text[/button] instead of [button url='...' style='...'] - Standard markdown images:  ✅ 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
313 lines
11 KiB
PHP
313 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Default Email Templates (DEPRECATED)
|
|
*
|
|
* @deprecated Use WooNooW\Email\DefaultTemplates instead
|
|
*
|
|
* This file is kept for backwards compatibility only.
|
|
* The new source of truth is /includes/Email/DefaultTemplates.php
|
|
* which contains clean markdown templates without HTML tags.
|
|
*
|
|
* TemplateProvider now uses the new Email\DefaultTemplates directly.
|
|
*
|
|
* @package WooNooW
|
|
*/
|
|
|
|
namespace WooNooW\Core\Notifications;
|
|
|
|
use WooNooW\Email\DefaultTemplates as NewDefaultTemplates;
|
|
|
|
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) {
|
|
// Get templates directly from this class
|
|
$allTemplates = self::get_all_templates();
|
|
|
|
// Check if event exists for this recipient type
|
|
if (isset($allTemplates[$event_id][$recipient_type])) {
|
|
return $allTemplates[$event_id][$recipient_type];
|
|
}
|
|
|
|
// Fallback
|
|
return [
|
|
'subject' => __('Notification from {store_name}', 'woonoow'),
|
|
'body' => '[card]' . __('You have a new notification.', 'woonoow') . '[/card]',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get all default templates (legacy method - kept for backwards compatibility)
|
|
*
|
|
* @return array
|
|
*/
|
|
private static function get_all_templates() {
|
|
// This method is now deprecated but kept for backwards compatibility
|
|
// Use WooNooW\Email\DefaultTemplates instead
|
|
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 url="{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 url="{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 url="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]
|
|
[button url="{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 url="{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 url="{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 url="{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 url="{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 url="{account_url}" style="solid"]' . __('Go to My Account', 'woonoow') . '[/button]
|
|
[button url="{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 url="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get all new templates (direct access to new class)
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_new_templates() {
|
|
return NewDefaultTemplates::get_all_templates();
|
|
}
|
|
|
|
/**
|
|
* Get default subject from new templates
|
|
*
|
|
* @param string $recipient_type 'staff' or 'customer'
|
|
* @param string $event_id Event ID
|
|
* @return string
|
|
*/
|
|
public static function get_default_subject($recipient_type, $event_id) {
|
|
return NewDefaultTemplates::get_default_subject($recipient_type, $event_id);
|
|
}
|
|
}
|