4 Developer Guide

Order Daemon is engineered with a “Surgeon’s Scalpel” and “Glass Box” philosophy, providing a precise, transparent, and extensible platform for developers. This guide covers the key extension points for integrating and customizing the plugin.

4.1 REST API & Webhooks

The plugin includes a modern REST API and webhook system, designed for programmatic management and integration with external services. These features are in a developer preview and may evolve in future updates.

REST API

Order Daemon provides endpoints for managing rules and discovering components, which is ideal for syncing configurations between environments or building custom dashboards.

  • Rule Management: Programmatically get and save automation rules via /wp-json/odcm/v1/rule/{id}.
  • Component Discovery: Fetch available triggers, conditions, and actions via /wp-json/odcm/v1/rule-builder/components.

Inbound Webhooks

The plugin can receive data from external services through dedicated webhook endpoints, enabling powerful integrations with payment gateways or automation tools like Zapier.

  • Gateway Endpoints: Order Daemon has built-in support for gateways like Stripe and PayPal, plus a generic adapter that can handle a wide variety of events. The webhook URL format is /wp-json/odcm/v1/webhooks/{gateway}.
  • Event Handling: The internal event router processes incoming webhooks and maps them to universal events for rule evaluation.

4.2 Extending with PHP (Hooks & Filters)

Order Daemon is built with a registry-based architecture that is designed to be extended. You can create your own custom components or use standard WordPress hooks and filters to modify the core behavior.

Creating Custom Rule Components

The plugin’s RuleComponentRegistry automatically discovers and registers component classes, allowing you to add your own custom Triggers, Conditions, and Actions. To create a custom component, you simply need to create a class that implements one of the provided PHP interfaces:

  • TriggerInterface
  • ConditionInterface
  • ActionInterface

The registry system will then make your component available in the Rule Builder UI.

Using Hooks and Filters

The plugin includes numerous WordPress action and filter hooks for deep customization. A powerful example is the odcm_order_has_conflicts filter, which allows you to programmatically prevent rules from running on certain orders.

Example: Exclude High-Value Orders from Automation
This snippet uses the filter to mark any order over $500 as having a conflict, which prevents Order Daemon from processing it automatically.

add_filter('odcm_order_has_conflicts', 'skip_high_value_orders', 10, 2);

function skip_high_value_orders($has_conflicts, $order_id) {
    if ($has_conflicts) {
        return true; // Another check has already flagged a conflict.
    }

    $order = wc_get_order($order_id);
    if (!$order) {
        return $has_conflicts;
    }

    // Skip orders over $500 for manual review.
    if ($order->get_total() > 500) {
        // This log entry will appear in the Insight Dashboard.
        odcm_log_custom_event(
            "Order #{$order_id} skipped: High value order requires manual review",
            ['order_total' => $order->get_total(), 'threshold' => 500],
            $order_id,
            'info'
        );
        return true; // Mark as having a conflict.
    }

    return false;
}

4.3 Custom Logging

The “Glass Box” philosophy means that transparency is a core feature. You can easily write your own events directly into the Order Daemon Insight Dashboard from your custom code. This is perfect for logging the activity of your own integrations and customizations, keeping all order-related events in one central place.

Use the global odcm_log_custom_event() function to add your entries to the audit trail.

Function Signature:

odcm_log_custom_event(
    string $summary,          // A human-readable description of the event.
    ?array $payload = null,   // An array of structured data for the details pane.
    ?int $order_id = null,    // The related WooCommerce order ID.
    string $status = 'info',  // Event status: 'success', 'error', 'warning', or 'info'.
    ?string $event_type = null // A unique, machine-readable event type slug.
);

As seen in the skip_high_value_orders example above, this function provides a simple yet powerful way to integrate your custom logic into the plugin’s detailed logging system.

Was this article helpful?

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