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
This commit is contained in:
dwindown
2025-11-15 20:05:50 +07:00
parent 550b3b69ef
commit 4471cd600f
45 changed files with 9194 additions and 508 deletions

View File

@@ -0,0 +1,791 @@
<?php
/**
* Default Email Templates for WooNooW
*
* Complete collection of ready-to-use email templates for online stores.
* These templates follow modern, minimal design principles and work perfectly
* without any customization required by store owners.
*
* Card Syntax:
* - [card] Default card with white background
* - [card type="success"] Green-themed card for positive messages
* - [card type="info"] Blue-themed card for information
* - [card type="warning"] Orange-themed card for warnings
* - [card type="hero"] Large header card with gradient background
*
* Button Syntax:
* [button url="{placeholder}"]Button Text[/button]
*
* @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() {
$templates = [
'customer' => [
'order_placed' => self::customer_order_placed(),
'order_processing' => self::customer_order_processing(),
'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(),
'new_customer' => self::customer_new_customer(),
],
'staff' => [
'order_placed' => self::staff_order_placed(),
'order_processing' => self::staff_order_processing(),
'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(),
],
];
/**
* Filter: woonoow_email_default_templates
*
* Allows plugins to add or modify default email templates
*
* @param array $templates Templates organized by recipient type and event
*/
return apply_filters('woonoow_email_default_templates', $templates);
}
/**
* 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' => 'Your order #{order_number} has been received',
'order_processing' => 'Your order #{order_number} is being processed',
'order_shipped' => 'Your order #{order_number} is on its way',
'order_completed' => 'Your order #{order_number} has arrived',
'order_cancelled' => 'Your order #{order_number} has been cancelled',
'payment_received' => 'Payment confirmed for order #{order_number}',
'payment_failed' => 'Payment failed for order #{order_number}',
'new_customer' => 'Welcome to {site_name}!',
],
'staff' => [
'order_placed' => '[New Order] #{order_number} from {customer_name}',
'order_processing' => '[Order Processing] #{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} - {order_total}',
'payment_failed' => '[Payment Failed] #{order_number}',
],
];
$subject = $subjects[$recipient][$event] ?? '';
/**
* Filter: woonoow_email_default_subject
*
* Allows plugins to modify default email subjects
*
* @param string $subject Default subject line
* @param string $recipient Recipient type ('customer' or 'staff')
* @param string $event Event ID
*/
return apply_filters('woonoow_email_default_subject', $subject, $recipient, $event);
}
// ========================================================================
// CUSTOMER TEMPLATES
// ========================================================================
/**
* Customer: Order Placed
* Sent immediately when customer places an order
*/
private static function customer_order_placed() {
return '[card type="hero"]
## Thank you for your order, {customer_name}!
We\'ve received your order and will begin processing it right away.
[/card]
[card]
**Order Number:** #{order_number}
**Order Date:** {order_date}
**Order Total:** {order_total}
[/card]
[card]
{order_items_table}
[/card]
[card]
**Payment Method:** {payment_method}
**Status:** Processing
[/card]
[button url="{order_url}"]View Order Details[/button]
[card type="info"]
**What happens next?**
Once we confirm your payment, we\'ll prepare your order for shipment and send you a tracking number. This usually takes 1-2 business days.
[/card]
[card type="basic"]
Need help? Contact us: {support_email}
[/card]';
}
/**
* Customer: Order Processing
* Sent when order payment is confirmed and ready for shipment
*/
private static function customer_order_processing() {
return '[card type="success"]
## Great news, {customer_name}!
Your order #{order_number} is confirmed and being prepared for shipment.
[/card]
[card]
**Order Number:** #{order_number}
**Order Total:** {order_total}
**Estimated Delivery:** 3-5 business days
[/card]
[card]
✓ Payment received
✓ Order is being packed
✓ You\'ll receive a shipping notification with tracking info
[/card]
[button url="{order_url}"]Track Your Order[/button]
[card type="info"]
Your order is on its way! You can track your shipment once we dispatch it.
[/card]
[card type="basic"]
Questions? We\'re here to help: {support_email}
[/card]';
}
/**
* Customer: Order Shipped
* Sent when order is dispatched
*/
private static function customer_order_shipped() {
return '[card type="success"]
## Your order #{order_number} has shipped!
Track your package and get real-time delivery updates.
[/card]
[card]
**Tracking Number:** {tracking_number}
**Carrier:** {shipping_carrier}
**Estimated Delivery:** 2-3 business days
[/card]
[button url="{tracking_url}"]Track Your Package[/button]
[card type="info"]
Your package is on its way to you. Click the button above to see the current location and estimated delivery date.
[/card]
[card]
**Order Details:**
Order #{order_number}
{order_items_table}
[/card]
[card type="basic"]
Need assistance? Contact {support_email}
[/card]';
}
/**
* Customer: Order Completed
* Sent when order is delivered
*/
private static function customer_order_completed() {
return '[card type="success"]
## Your order #{order_number} has arrived!
We hope you love your purchase. Your feedback helps us improve.
[/card]
[card]
**Order Number:** #{order_number}
**Delivery Date:** {completion_date}
[/card]
[button url="{review_url}"]Share Your Review[/button]
[card type="info"]
Your review is valuable to us and helps other customers make informed decisions. Plus, reviewers often get special discounts on future purchases!
[/card]
[card]
**Order Summary:**
{order_items_table}
[/card]
[card type="basic"]
Questions or issues with your order? We\'re here to help.
Contact: {support_email}
[/card]';
}
/**
* Customer: Order Cancelled
* Sent when order is cancelled by customer or staff
*/
private static function customer_order_cancelled() {
return '[card type="warning"]
## Your order #{order_number} has been cancelled.
[/card]
[card]
**Order Number:** #{order_number}
**Cancellation Date:** {order_date}
**Order Total:** {order_total}
[/card]
[card type="info"]
If you made a payment, a refund will be processed to your original payment method within 5-7 business days.
[/card]
[card]
**Items:**
{order_items_table}
[/card]
[button url="{shop_url}"]Continue Shopping[/button]
[card type="basic"]
We\'d love to know why you cancelled. Feel free to reach out to us at {support_email} if there\'s anything we can help with.
[/card]';
}
/**
* Customer: Payment Received
* Sent when payment is successfully processed
*/
private static function customer_payment_received() {
return '[card type="success"]
## Payment confirmed!
Thank you for your payment. Your order #{order_number} is now being processed.
[/card]
[card]
**Amount Paid:** {order_total}
**Payment Method:** {payment_method}
**Transaction ID:** {transaction_id}
**Date:** {payment_date}
[/card]
[card type="info"]
Your order is now being prepared for shipment. You\'ll receive a tracking notification within 1-2 business days.
[/card]
[button url="{order_url}"]View Your Order[/button]
[card]
Please keep this email for your records.
[/card]';
}
/**
* Customer: Payment Failed
* Sent when payment processing fails
*/
private static function customer_payment_failed() {
return '[card type="warning"]
## Payment could not be processed
We were unable to complete the payment for order #{order_number}. Your order is still reserved, but we need you to update your payment information.
[/card]
[card]
**Order Number:** #{order_number}
**Order Total:** {order_total}
**Reason:** Payment declined
[/card]
[card]
**Common reasons:**
• Insufficient funds
• Incorrect card details
• Card expired or blocked
• Bank security check
[/card]
[button url="{payment_retry_url}"]Update Payment Method[/button]
[card type="info"]
Your order is on hold. Please update your payment information to proceed. If you continue to experience issues, contact your bank or reach out to us.
[/card]
[card type="basic"]
Questions? {support_email}
[/card]';
}
/**
* Customer: New Customer
* Sent when customer creates an account
*/
private static function customer_new_customer() {
return '[card type="hero"]
# Welcome to {site_name}, {customer_name}!
Your account is ready. Let\'s get you started.
[/card]
[card]
**Account Benefits:**
✓ Faster checkout on your next order
✓ Order history and tracking
✓ Exclusive member offers and updates
✓ Wishlist and saved items
✓ Easy returns and exchanges
[/card]
[button url="{my_account_url}"]Access Your Account[/button]
[button url="{shop_url}"]Start Shopping[/button]
[card type="info"]
We\'re excited to have you as part of our community. Happy shopping!
[/card]
[card type="basic"]
Need help? Contact {support_email}
[/card]';
}
/**
* Customer: VIP Upgraded
* Sent when customer is upgraded to VIP status
*/
private static function customer_vip_upgraded() {
return '[card type="success"]
## Congratulations, {customer_name}!
You\'re now a VIP member.
[/card]
[card]
**Your VIP Perks:**
✓ Exclusive early access to new products
✓ Special VIP-only discounts
✓ Priority customer support
✓ Free shipping on orders over {vip_free_shipping_threshold}
✓ Birthday month bonus gift
[/card]
[button url="{vip_dashboard_url}"]View Your VIP Dashboard[/button]
[card type="info"]
Simply shop as usual—your VIP benefits are automatically applied to all your orders. Thank you for your continued loyalty!
[/card]
[card type="basic"]
Questions? {support_email}
[/card]';
}
// ========================================================================
// STAFF TEMPLATES
// ========================================================================
/**
* Staff: Order Placed
* Notifies staff when customer places an order
*/
private static function staff_order_placed() {
return '[card type="hero"]
# New order received!
A customer has placed a new order. Please review and process.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Order Date:** {order_date}
**Order Total:** {order_total}
**Payment Status:** {payment_status}
[/card]
[card]
**Customer Contact:**
Email: {customer_email}
Phone: {customer_phone}
[/card]
[card]
**Items Ordered:**
{order_items_table}
[/card]
[card]
**Delivery Address:**
{shipping_address}
[/card]
[button url="{order_url}"]Process This Order[/button]
[card type="info"]
If payment status is "pending", please follow up with the customer or wait for payment confirmation before processing.
[/card]';
}
/**
* Staff: Order Processing
* Notifies staff when order is confirmed and ready to process
*/
private static function staff_order_processing() {
return '[card type="success"]
## Order confirmed and ready to process
Order #{order_number} is confirmed. Payment has been received. Begin preparation.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Order Total:** {order_total}
**Confirmed Date:** {order_date}
[/card]
[card]
**Items to Prepare:**
{order_items_table}
[/card]
[card]
**Action Items:**
• Verify inventory and pick items
• Quality check
• Pack securely
• Generate shipping label
• Update order status when shipped
[/card]
[button url="{order_url}"]View Full Order[/button]';
}
/**
* Staff: Order Shipped
* Notifies staff when order is marked as shipped
*/
private static function staff_order_shipped() {
return '[card type="success"]
## Order shipped
Order #{order_number} has been dispatched. Customer notified with tracking info.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Tracking Number:** {tracking_number}
**Carrier:** {shipping_carrier}
**Shipped Date:** {order_date}
[/card]
[button url="{order_url}"]View Order[/button]
[card type="info"]
Customer has been automatically notified via email with tracking details.
[/card]';
}
/**
* Staff: Order Completed
* Notifies staff when order is completed/delivered
*/
private static function staff_order_completed() {
return '[card type="success"]
## Order completed
Order #{order_number} has been delivered to customer. All steps completed.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Order Total:** {order_total}
**Completed Date:** {order_date}
[/card]
[card]
**Order Timeline:**
✓ Order placed
✓ Payment received
✓ Order prepared and packed
✓ Shipped
✓ Delivered
[/card]
[button url="{order_url}"]View Order[/button]
[card type="info"]
Customer has been notified and invited to leave a review.
[/card]';
}
/**
* Staff: Order Cancelled
* Notifies staff when order is cancelled
*/
private static function staff_order_cancelled() {
return '[card type="warning"]
## Order cancelled
Order #{order_number} has been cancelled. Please process refund if payment was received.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Order Total:** {order_total}
**Cancelled Date:** {order_date}
[/card]
[card]
**Items (will not ship):**
{order_items_table}
[/card]
[card]
**Action Items:**
• If payment received: Process refund to original payment method
• Update inventory for cancelled items
• Check warehouse if order was already being prepared
• Confirm cancellation with customer
[/card]
[button url="{order_url}"]View Order & Process Refund[/button]
[card type="info"]
Customer has been notified of the cancellation.
[/card]';
}
/**
* Staff: Payment Received
* Notifies staff when payment is successfully received
*/
private static function staff_payment_received() {
return '[card type="success"]
## Payment received
Payment has been successfully processed for order #{order_number}. Ready to begin order processing.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Amount:** {order_total}
**Payment Method:** {payment_method}
**Transaction ID:** {transaction_id}
**Date:** {payment_date}
[/card]
[card]
**Next Steps:**
• Confirm the order
• Begin item preparation
• Prepare shipping label
• Update customer with tracking info
[/card]
[button url="{order_url}"]Process Order[/button]
[card type="info"]
Order is now confirmed and ready for fulfillment.
[/card]';
}
/**
* Staff: Payment Failed
* Notifies staff when payment processing fails
*/
private static function staff_payment_failed() {
return '[card type="warning"]
## Payment failed
Payment processing failed for order #{order_number}. Order is on hold pending payment.
[/card]
[card]
**Order Number:** #{order_number}
**Customer:** {customer_name}
**Amount:** {order_total}
**Payment Method:** {payment_method}
**Failed Date:** {payment_date}
[/card]
[card]
**Action Items:**
• Customer has been notified to update payment
• Check order status after 24 hours
• If still unpaid, consider cancelling
• Contact customer if needed
[/card]
[button url="{order_url}"]View Order Details[/button]
[card type="info"]
Order is reserved but will be cancelled automatically if payment is not received within 24-48 hours (configure this in settings).
[/card]';
}
}

View File

@@ -0,0 +1,709 @@
<?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]';
}
}

View File

@@ -0,0 +1,338 @@
# Email Template Usage Guide
## How to Use Default Templates
### Quick Start
The `DefaultTemplates` class provides production-ready email templates for all notification types.
```php
use WooNooW\Email\DefaultTemplates;
// Get all templates
$templates = DefaultTemplates::get_all_templates();
// Get specific template
$customerOrderPlaced = $templates['customer']['order_placed'];
$staffOrderPlaced = $templates['staff']['order_placed'];
// Get default subject
$subject = DefaultTemplates::get_default_subject('customer', 'order_placed');
// Returns: "Your order #{order_number} has been received"
```
---
## Template Structure
### Available Recipients
- `customer` - Emails sent to customers
- `staff` - Emails sent to store staff/admin
### Available Events
**Customer Events:**
- `order_placed` - When customer places an order
- `order_confirmed` - When order is confirmed by staff
- `order_shipped` - When order is shipped
- `order_completed` - When order is delivered
- `order_cancelled` - When order is cancelled
- `payment_received` - When payment is successful
- `payment_failed` - When payment fails
- `customer_registered` - When customer creates account
- `customer_vip_upgraded` - When customer becomes VIP
**Staff Events:**
- `order_placed` - New order notification
- `order_confirmed` - Order confirmed notification
- `order_shipped` - Order shipped notification
- `order_completed` - Order completed notification
- `order_cancelled` - Order cancelled notification
- `payment_received` - Payment received notification
- `payment_failed` - Payment failed notification
---
## Variable Replacement
Templates use `{variable_name}` syntax. Replace these with actual data before sending:
```php
$template = $templates['customer']['order_placed'];
$subject = DefaultTemplates::get_default_subject('customer', 'order_placed');
// Replace variables
$variables = [
'customer_name' => $order->get_billing_first_name(),
'order_number' => $order->get_order_number(),
'order_date' => $order->get_date_created()->format('F j, Y'),
'order_total' => $order->get_formatted_order_total(),
'order_url' => $order->get_view_order_url(),
'payment_method' => $order->get_payment_method_title(),
'order_item_table' => $this->generate_order_items_table($order),
'support_email' => get_option('admin_email'),
'current_year' => date('Y'),
'site_name' => get_bloginfo('name'),
];
foreach ($variables as $key => $value) {
$template = str_replace('{' . $key . '}', $value, $template);
$subject = str_replace('{' . $key . '}', $value, $subject);
}
```
---
## Complete Variable Reference
### Order Variables
```php
'{order_number}' // Order ID/number
'{order_date}' // Order creation date
'{order_total}' // Total amount with currency
'{order_url}' // Link to view order
'{order_item_table}' // HTML table of order items
'{completion_date}' // Order completion date
```
### Customer Variables
```php
'{customer_name}' // Customer's full name
'{customer_email}' // Customer's email address
'{customer_phone}' // Customer's phone number
```
### Payment Variables
```php
'{payment_method}' // Payment method name
'{payment_status}' // Payment status
'{payment_date}' // Payment date
'{transaction_id}' // Payment transaction ID
'{payment_retry_url}' // URL to retry failed payment
```
### Shipping Variables
```php
'{tracking_number}' // Shipment tracking number
'{tracking_url}' // Tracking URL
'{shipping_carrier}' // Carrier name (e.g., "FedEx")
'{shipping_address}' // Full shipping address
'{billing_address}' // Full billing address
```
### URL Variables
```php
'{order_url}' // Order details page
'{review_url}' // Leave review page
'{shop_url}' // Shop homepage
'{my_account_url}' // Customer account page
'{vip_dashboard_url}' // VIP member dashboard
```
### Store Variables
```php
'{site_name}' // Store name
'{store_url}' // Store homepage URL
'{support_email}' // Support email address
'{current_year}' // Current year (for copyright)
```
### VIP Variables
```php
'{vip_free_shipping_threshold}' // Free shipping threshold for VIP
```
---
## Example: Sending Order Placed Email
```php
use WooNooW\Email\DefaultTemplates;
class OrderNotification {
public function send_order_placed_email($order_id) {
$order = wc_get_order($order_id);
// Get template and subject
$templates = DefaultTemplates::get_all_templates();
$body = $templates['customer']['order_placed'];
$subject = DefaultTemplates::get_default_subject('customer', 'order_placed');
// Prepare variables
$variables = [
'customer_name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
'order_number' => $order->get_order_number(),
'order_date' => $order->get_date_created()->format('F j, Y g:i A'),
'order_total' => $order->get_formatted_order_total(),
'order_url' => $order->get_view_order_url(),
'payment_method' => $order->get_payment_method_title(),
'order_item_table' => $this->generate_order_items_table($order),
'support_email' => get_option('woocommerce_email_from_address'),
'current_year' => date('Y'),
'site_name' => get_bloginfo('name'),
];
// Replace variables in body and subject
foreach ($variables as $key => $value) {
$body = str_replace('{' . $key . '}', $value, $body);
$subject = str_replace('{' . $key . '}', $value, $subject);
}
// Convert markdown/card syntax to HTML
$html = $this->parse_email_template($body);
// Send email
$headers = ['Content-Type: text/html; charset=UTF-8'];
wp_mail(
$order->get_billing_email(),
$subject,
$html,
$headers
);
}
private function generate_order_items_table($order) {
$html = '<table style="width: 100%; border-collapse: collapse; margin: 16px 0;">';
$html .= '<thead><tr style="background: #f5f5f5;">';
$html .= '<th style="padding: 12px; text-align: left; border-bottom: 2px solid #ddd;">Product</th>';
$html .= '<th style="padding: 12px; text-align: center; border-bottom: 2px solid #ddd;">Qty</th>';
$html .= '<th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">Price</th>';
$html .= '</tr></thead><tbody>';
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$html .= '<tr>';
$html .= '<td style="padding: 12px; border-bottom: 1px solid #eee;">';
$html .= '<strong>' . $item->get_name() . '</strong>';
$html .= '</td>';
$html .= '<td style="padding: 12px; text-align: center; border-bottom: 1px solid #eee;">' . $item->get_quantity() . '</td>';
$html .= '<td style="padding: 12px; text-align: right; border-bottom: 1px solid #eee;">' . wc_price($item->get_total()) . '</td>';
$html .= '</tr>';
}
$html .= '</tbody></table>';
return $html;
}
private function parse_email_template($content) {
// Parse [card] blocks
$content = preg_replace_callback(
'/\[card(?:\s+type="([^"]+)")?\](.*?)\[\/card\]/s',
function($matches) {
$type = $matches[1] ?? 'default';
$cardContent = $matches[2];
$class = 'card' . ($type !== 'default' ? ' card-' . $type : '');
return '<div class="' . $class . '">' . $cardContent . '</div>';
},
$content
);
// Parse [button] shortcodes
$content = preg_replace(
'/\[button\s+url="([^"]+)"(?:\s+style="([^"]+)")?\]([^\[]+)\[\/button\]/',
'<p style="text-align: center;"><a href="$1" class="button">$3</a></p>',
$content
);
// Parse markdown basics
$content = preg_replace('/\*\*([^*]+)\*\*/', '<strong>$1</strong>', $content);
$content = preg_replace('/^---$/m', '<hr>', $content);
// Wrap in email template
return $this->wrap_in_email_template($content);
}
private function wrap_in_email_template($content) {
// Get email settings from database
$settings = get_option('woonoow_email_settings', []);
$primaryColor = $settings['primary_color'] ?? '#7f54b3';
$heroGradientStart = $settings['hero_gradient_start'] ?? '#667eea';
$heroGradientEnd = $settings['hero_gradient_end'] ?? '#764ba2';
return '
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; background: #f8f8f8; margin: 0; padding: 20px; }
.container { max-width: 600px; margin: 0 auto; }
.card { background: #ffffff; border-radius: 8px; margin-bottom: 24px; padding: 32px 40px; }
.card-hero { background: linear-gradient(135deg, ' . $heroGradientStart . ' 0%, ' . $heroGradientEnd . ' 100%); color: #ffffff; }
.card-success { background: linear-gradient(135deg, ' . $heroGradientStart . ' 0%, ' . $heroGradientEnd . ' 100%); color: #ffffff; }
.card-info { background: #f0f7ff; border: 1px solid #0071e3; }
.card-warning { background: #fff8e1; border: 1px solid #ff9800; }
.button { display: inline-block; background: ' . $primaryColor . '; color: #ffffff; padding: 14px 28px; border-radius: 6px; text-decoration: none; font-weight: 600; }
hr { border: none; border-top: 1px solid #ddd; margin: 20px 0; }
</style>
</head>
<body>
<div class="container">
' . $content . '
</div>
</body>
</html>';
}
}
```
---
## Integration with WooCommerce
Hook into WooCommerce order status changes:
```php
add_action('woocommerce_order_status_processing', 'send_order_placed_email', 10, 1);
add_action('woocommerce_order_status_completed', 'send_order_completed_email', 10, 1);
add_action('woocommerce_order_status_cancelled', 'send_order_cancelled_email', 10, 1);
```
---
## Customization
Store owners can customize templates in the admin panel:
1. Navigate to Settings > Notifications
2. Select recipient (Customer/Staff) and event
3. Edit template using:
- **Visual Builder** - Drag-and-drop blocks
- **Code Mode** - Edit markdown/HTML directly
- **Preview** - See live preview with branding
Templates support:
- Custom branding colors
- Logo upload
- Social media links
- Custom footer text
- Variable insertion
---
## Best Practices
1. **Always replace variables** before sending emails
2. **Test emails** with sample data first
3. **Use appropriate card types**:
- `hero` - Welcome messages, big announcements
- `success` - Positive confirmations
- `info` - Informational messages
- `warning` - Alerts, issues
- `default` - General content
4. **Keep templates clean** - Don't over-customize
5. **Use variables** instead of hardcoding data
6. **Test on mobile** - Emails are responsive
---
## Support
For questions or issues:
- Check `EMAIL_BUILDER_COMPLETE.md` for system overview
- Review template syntax in `DefaultTemplates.php`
- Test in admin panel Preview tab before sending
---
**Templates are production-ready and require no modification to work!**