3.1 Technical Overview

The Order Daemon is built with modern PHP practices and designed to be both performant and extensible. It features a sophisticated registry-based architecture, dual-table audit logging system, and comprehensive asynchronous processing pipeline that integrates deeply with WooCommerce while maintaining clear separation of concerns.

Core Architecture

The plugin’s architecture is built around several key components that work together to provide a robust, extensible completion management system:

1. Registry-Based Component System

The plugin uses a sophisticated dual-registry architecture to manage all available triggers, conditions, and actions:

  • OptionRegistry: UI-focused registry for admin interface components with entitlement integration
  • RuleComponentRegistry: Execution-focused registry with auto-discovery of component classes
  • FilterRegistry: Manages audit log filtering capabilities
  • LogRegistries: Defines event types and status classifications
// Example: Accessing the UI registry for admin interfaces
$registry = odcm_get_registry_instance();
$triggers = $registry->get_triggers();
$conditions = $registry->get_conditions();
$actions = $registry->get_actions();

// Example: Component registry for rule execution (auto-discovered)
$component_registry = RuleComponentRegistry::instance();
$trigger_component = $component_registry->get_trigger('payment_complete');
$condition_component = $component_registry->get_condition('order_total');

This dual-registry system enables third-party developers to extend the plugin with custom options while maintaining consistency, performance, and proper separation between UI and execution concerns.

2. Completion Rules as Custom Post Type (`odcm_order_rule`)

  • All completion rules are stored as posts with the type odcm_order_rule
  • Rule settings and conditions are saved as JSON metadata against the rule post
  • The menu_order attribute determines rule priority, with lower numbers executing first
  • Rules support complex condition logic and multiple action execution

3. Dual-Table Audit Logging System

The plugin implements a sophisticated logging architecture optimized for performance and scalability:

  • Primary Table (wp_odcm_audit_log): Core event data with optimized indexes
  • Payload Table (wp_odcm_audit_log_payloads): Separate storage for detailed event data
  • Asynchronous Processing: All logging operations use Action Scheduler for non-blocking execution
  • Registry-Based Events: Standardized event types with dynamic summary generation
// Example: Custom event logging
odcm_log_custom_event(
    'Custom integration processed order #123',
    ['integration' => 'my_plugin', 'status' => 'success'],
    123, // order_id
    'success'
);

4. The `Executor` Class

The OrderDaemon\CompletionManager\Core\Executor class orchestrates the entire order processing workflow:

  • Validates order objects and checks for conflicts
  • Evaluates rules using the Evaluator class with JSON-based rule definitions
  • Executes actions through a standardized component interface
  • Integrates with the audit logging system for full traceability
  • Includes performance monitoring and slow execution warnings

5. Action Scheduler Integration

All heavy processing operations are handled asynchronously:

  • Order processing is queued via Action Scheduler
  • Audit log entries are processed in background
  • Prevents performance impact on checkout and order processing
  • Provides reliability and retry capabilities for failed operations
  • Supports both traditional and Block-based checkout flows; Block Checkout integration is observation-only and processed asynchronously via the odcm_process_block_checkout_observation job (group: odcm-block-checkout)

Execution Flow

The plugin follows a sophisticated execution flow designed for reliability and extensibility:

1. Trigger Phase

  • Process begins when WooCommerce hooks fire (e.g., woocommerce_order_status_processing)
  • Multiple trigger types supported: order status changes, payment completion, manual triggers
  • Action Scheduler queues the order for processing to prevent blocking

2. Validation Phase

// Order validation and conflict checking
$order = wc_get_order($order_id);
if (!$order || $this->should_skip_order_due_to_conflicts($order)) {
    return; // Skip processing
}

3. Rule Evaluation Phase

  • Active rules are fetched and ordered by priority
  • Each rule’s conditions are evaluated using the Evaluator class
  • First matching rule wins (priority-based execution)
  • All evaluation steps are logged for audit trail

4. Action Execution Phase

  • Matching rule’s actions are executed in sequence
  • Each action is validated and executed through the component registry system
  • Pre-commit revalidation ensures order state hasn’t changed during processing
  • Success/failure is logged with detailed context
  • Multiple actions per rule are supported (primary + secondary actions)

5. Audit Logging Phase

  • All events are logged asynchronously via Action Scheduler
  • Registry-based event types ensure consistent categorization
  • Detailed payload data is stored separately for performance
  • Events include full context for debugging and compliance

Extension Points

The plugin provides numerous extension points for developers:

Registry Extensions

// Register custom UI component for admin interface
$registry = odcm_get_registry_instance();
$registry->register_trigger([
    'id' => 'my_custom_trigger',
    'label' => 'My Custom Trigger',
    'description' => 'Triggers when my condition is met',
    'capability' => 'trigger_custom', // Required for entitlement system
    'render_callback' => 'my_render_function'
]);

// For execution components, create classes implementing the appropriate interfaces
// These are auto-discovered by the RuleComponentRegistry
class MyCustomTrigger implements TriggerInterface {
    public function get_id(): string { return 'my_custom_trigger'; }
    public function get_label(): string { return 'My Custom Trigger'; }
    // ... implement other required methods
}

Hook Integration

  • Comprehensive filter and action hooks throughout the execution flow
  • Custom logging API for third-party integrations
  • Order conflict detection filters
  • Rule evaluation filters

Database Integration

  • Direct access to audit log tables for reporting
  • Standardized schema for third-party queries
  • Performance-optimized indexes for common query patterns

Performance Considerations

The plugin is designed with performance as a primary concern:

  • Asynchronous Processing: Heavy operations don’t block user requests
  • Optimized Queries: Minimal database queries with efficient indexing
  • Registry Caching: Option registries are cached in memory
  • Conditional Loading: Components load only when needed
  • Dual-Table Design: Separates frequently accessed data from detailed payloads

Security Features

  • Capability Checks: All admin operations require appropriate permissions
  • Nonce Validation: Forms include proper CSRF protection
  • Data Sanitization: All input is sanitized and validated
  • SQL Injection Prevention: Prepared statements throughout
  • Output Escaping: All output is properly escaped

This architecture provides a solid foundation for both basic automation needs and complex enterprise-level integrations while maintaining WordPress best practices and performance standards.

WooCommerce Integration Deep Dive

Order Daemon maintains a sophisticated integration with WooCommerce’s order processing pipeline:

Hook Integration Points

  • woocommerce_checkout_order_processed: Automatic scheduling (not user-selectable)
  • woocommerce_payment_complete: Primary completion trigger
  • woocommerce_order_status_*: Status change triggers
  • woocommerce_order_fully_refunded: Cleanup and reversal handling

Execution Context

The plugin receives rich context at each integration point, including:

  • Order object with full product and customer data
  • Payment gateway information and transaction details
  • Previous and current order statuses
  • Timing and sequence information

Asynchronous Processing Benefits

  • No impact on checkout performance or conversion rates
  • Reliable processing even during traffic spikes
  • Automatic retry for failed operations
  • Full audit trail of all processing attempts

Integration with WooCommerce APIs

  • Respects WooCommerce’s status change hooks and filters
  • Maintains compatibility with order management plugins
  • Preserves all native WooCommerce functionality

Was this article helpful?

  • Loading...
Table of Contents
  • Loading...