These hooks enable you to add new rule components, integrate external services, and build custom automation logic. Use these to extend Order Daemon’s capabilities beyond the built-in features.
Component Registration Hooks
Filter: odcm_rule_components
Register custom triggers, conditions, and actions.
Parameters:
$components(array) – Array of component arrays keyed by type
Returns: Modified components array
Component Array Structure:
[
'triggers' => [TriggerInterface, ...],
'conditions' => [ConditionInterface, ...],
'actions' => [ActionInterface, ...]
]
Example:
add_filter('odcm_rule_components', function($components) {
// Add custom condition
$components['conditions'][] = new CustomInventoryCondition();
// Add custom action
$components['actions'][] = new CustomEmailAction();
// Add custom trigger
$components['triggers'][] = new CustomWebhookTrigger();
return $components;
});
class CustomInventoryCondition implements ConditionInterface {
public function get_id(): string {
return 'inventory_level';
}
public function get_label(): string {
return __('Inventory Level', 'your-textdomain');
}
public function get_description(): string {
return __('Check product inventory levels', 'your-textdomain');
}
public function get_capability(): string {
return 'core'; // or 'premium' for Pro-only components
}
public function evaluate(WC_Order $order, array $settings): bool {
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$stock = $product->get_stock_quantity();
if ($stock < ($settings['min_stock'] ?? 0)) {
return false;
}
}
return true;
}
public function get_settings_schema(): array {
return [
'type' => 'object',
'properties' => [
'min_stock' => [
'type' => 'integer',
'minimum' => 0,
'default' => 1
]
],
'required' => ['min_stock']
];
}
}
Gateway Integration Hooks
Filter: odcm_gateway_adapters
Register custom webhook gateway adapters.
Parameters:
$adapters(array) – Array of gateway adapter instances
Returns: Modified adapters array
Example:
add_filter('odcm_gateway_adapters', function($adapters) {
$adapters[] = new CustomPaymentGatewayAdapter();
return $adapters;
});
class CustomPaymentGatewayAdapter extends AbstractGatewayAdapter {
public function get_id(): string {
return 'custom_gateway';
}
public function get_name(): string {
return __('Custom Payment Gateway', 'your-textdomain');
}
public function get_supported_events(): array {
return ['payment.completed', 'payment.failed', 'subscription.renewed'];
}
public function process_webhook(array $payload): UniversalEvent {
// Extract order ID from gateway-specific payload
$order_id = $this->extract_order_id($payload);
// Map gateway event to universal event type
$event_type = $this->map_event_type($payload['event_type'] ?? '');
// Create universal event
return new UniversalEvent($event_type, $order_id, $payload);
}
public function verify_signature(array $headers, string $payload): bool {
$provided_signature = $headers['X-Custom-Signature'] ?? '';
$secret = $this->get_webhook_secret();
$expected_signature = hash_hmac('sha256', $payload, $secret);
return hash_equals($expected_signature, $provided_signature);
}
protected function extract_order_id(array $payload): ?int {
// Extract order ID from custom gateway payload structure
return (int) ($payload['order_reference'] ?? null);
}
protected function map_event_type(string $gateway_event): string {
$event_map = [
'payment.completed' => 'order_paid',
'payment.failed' => 'payment_failed',
'subscription.renewed' => 'subscription_renewed'
];
return $event_map[$gateway_event] ?? 'unknown_event';
}
protected function get_webhook_secret(): string {
return get_option('custom_gateway_webhook_secret', '');
}
}
Custom Logging Hooks
Filter: odcm_audit_log_components
Add custom audit log component renderers.
Parameters:
$renderers(array) – Array of component renderer classes
Returns: Modified renderers array
Example:
add_filter('odcm_audit_log_components', function($renderers) {
$renderers['custom_email_action'] = new CustomEmailActionRenderer();
return $renderers;
});
class CustomEmailActionRenderer {
public function render(array $component_data, array $context): array {
return [
'title' => __('Custom Email Sent', 'your-textdomain'),
'status' => $component_data['success'] ? 'success' : 'error',
'details' => sprintf(
__('Email sent to %s with subject: %s', 'your-textdomain'),
$component_data['recipient'],
$component_data['subject']
),
'metadata' => [
'delivery_time' => $component_data['delivery_time'] ?? null,
'message_id' => $component_data['message_id'] ?? null
]
];
}
}
Function: odcm_log_custom_event()
Log custom events to the audit trail.
Parameters:
$summary(string) – Human-readable event description$payload(array, optional) – Structured event data$order_id(int, optional) – Related order ID$status(string, optional) – Event status: ‘success’, ‘error’, ‘warning’, ‘info’$event_type(string, optional) – Machine-readable event type
Example:
// Log external API integration
function sync_with_external_crm($order_id) {
try {
$response = wp_remote_post('https://api.crm.example.com/orders', [
'body' => wp_json_encode($this->prepare_order_data($order_id))
]);
if (is_wp_error($response)) {
throw new Exception($response->get_error_message());
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
odcm_log_custom_event(
"Order synchronized with CRM successfully",
[
'crm_id' => $data['crm_order_id'] ?? null,
'sync_time' => current_time('mysql'),
'api_response' => $data
],
$order_id,
'success',
'crm_sync'
);
} catch (Exception $e) {
odcm_log_custom_event(
"Failed to synchronize order with CRM: " . $e->getMessage(),
[
'error' => $e->getMessage(),
'error_code' => $e->getCode()
],
$order_id,
'error',
'crm_sync_failed'
);
}
}
Settings and Configuration Hooks
Filter: odcm_settings_sections
Add custom settings sections to the plugin.
Parameters:
$sections(array) – Array of settings sections
Returns: Modified sections array
Example:
add_filter('odcm_settings_sections', function($sections) {
$sections['external_integrations'] = [
'title' => __('External Integrations', 'your-textdomain'),
'description' => __('Configure third-party service integrations', 'your-textdomain'),
'fields' => [
'crm_api_key' => [
'type' => 'password',
'label' => __('CRM API Key', 'your-textdomain'),
'description' => __('API key for CRM integration', 'your-textdomain')
],
'enable_inventory_sync' => [
'type' => 'checkbox',
'label' => __('Enable Inventory Sync', 'your-textdomain'),
'description' => __('Sync inventory levels with external system', 'your-textdomain')
]
]
];
return $sections;
});
Filter: odcm_component_settings_ui
Customize component settings UI rendering.
Parameters:
$ui_config(array) – UI configuration for component settings$component_id(string) – Component identifier$component_type(string) – Component type (trigger, condition, action)
Returns: Modified UI configuration
Example:
add_filter('odcm_component_settings_ui', function($ui_config, $component_id, $component_type) {
// Add custom UI for inventory condition
if ($component_id === 'inventory_level') {
$ui_config['fields']['min_stock']['ui_component'] = 'number-input';
$ui_config['fields']['min_stock']['props'] = [
'min' => 0,
'max' => 9999,
'step' => 1,
'placeholder' => __('Enter minimum stock level', 'your-textdomain')
];
}
return $ui_config;
}, 10, 3);
Third-Party Service Hooks
Action: odcm_external_service_connected
Fired when an external service connection is established.
Parameters:
$service_id(string) – Service identifier$connection_data(array) – Connection details$user_id(int) – User who made the connection
Example:
add_action('odcm_external_service_connected', function($service_id, $connection_data, $user_id) {
if ($service_id === 'zapier') {
// Initialize Zapier integration
$this->setup_zapier_webhooks($connection_data['webhook_url']);
// Log the connection
odcm_log_custom_event(
"Zapier integration connected",
[
'webhook_url' => $connection_data['webhook_url'],
'connected_by' => $user_id
],
null,
'success',
'external_service_connected'
);
}
});
Filter: odcm_external_service_data
Modify data sent to external services.
Parameters:
$data(array) – Data to be sent$service_id(string) – Target service identifier$order_id(int) – Related order ID$context(array) – Additional context
Returns: Modified data array
Example:
add_filter('odcm_external_service_data', function($data, $service_id, $order_id, $context) {
if ($service_id === 'analytics_platform') {
// Add custom analytics data
$order = wc_get_order($order_id);
$data['custom_fields'] = [
'customer_segment' => get_user_meta($order->get_customer_id(), 'segment', true),
'acquisition_channel' => $order->get_meta('_acquisition_channel'),
'lifetime_value' => $this->calculate_customer_ltv($order->get_customer_id())
];
// Add product analytics
$data['products'] = [];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$data['products'][] = [
'sku' => $product->get_sku(),
'category' => $this->get_primary_category($product->get_id()),
'margin' => $this->calculate_product_margin($product->get_id())
];
}
}
return $data;
}, 10, 4);
Custom Workflow Hooks
Filter: odcm_workflow_steps
Define custom workflow steps for complex automations.
Parameters:
$steps(array) – Array of workflow step definitions$workflow_id(string) – Workflow identifier
Returns: Modified steps array
Example:
add_filter('odcm_workflow_steps', function($steps, $workflow_id) {
if ($workflow_id === 'complex_fulfillment') {
$steps['inventory_check'] = [
'label' => __('Check Inventory', 'your-textdomain'),
'handler' => [$this, 'check_inventory_availability'],
'timeout' => 30,
'retry_on_failure' => true,
'max_retries' => 3
];
$steps['allocate_stock'] = [
'label' => __('Allocate Stock', 'your-textdomain'),
'handler' => [$this, 'allocate_inventory'],
'depends_on' => ['inventory_check'],
'timeout' => 60
];
$steps['notify_warehouse'] = [
'label' => __('Notify Warehouse', 'your-textdomain'),
'handler' => [$this, 'send_warehouse_notification'],
'depends_on' => ['allocate_stock'],
'async' => true
];
}
return $steps;
}, 10, 2);
Action: odcm_workflow_step_completed
Fired when a workflow step completes.
Parameters:
$step_id(string) – Step identifier$workflow_id(string) – Workflow identifier$result(array) – Step execution result$order_id(int) – Related order ID
Example:
add_action('odcm_workflow_step_completed', function($step_id, $workflow_id, $result, $order_id) {
if ($workflow_id === 'complex_fulfillment' && $step_id === 'inventory_check') {
if (!$result['success']) {
// Handle inventory shortage
$this->handle_inventory_shortage($order_id, $result['shortage_details']);
} else {
// Continue to next step
$this->trigger_next_workflow_step($workflow_id, $order_id);
}
}
});
Data Export and Import Hooks
Filter: odcm_export_data
Modify data included in exports.
Parameters:
$export_data(array) – Data to be exported$export_type(string) – Type of export (rules, logs, settings)$options(array) – Export options
Returns: Modified export data
Example:
add_filter('odcm_export_data', function($export_data, $export_type, $options) {
if ($export_type === 'rules' && !empty($options['include_custom_data'])) {
// Add custom rule metadata
foreach ($export_data['rules'] as &$rule) {
$rule['custom_metadata'] = get_post_meta($rule['id'], '_custom_rule_data', true);
$rule['usage_stats'] = $this->get_rule_usage_stats($rule['id']);
}
}
return $export_data;
}, 10, 3);
Action: odcm_import_data_processed
Fired after import data has been processed.
Parameters:
$imported_data(array) – Data that was imported$import_results(array) – Results of the import process$user_id(int) – User who performed the import
Example:
add_action('odcm_import_data_processed', function($imported_data, $import_results, $user_id) {
// Custom post-import processing
if (isset($imported_data['rules'])) {
foreach ($imported_data['rules'] as $rule_data) {
if (isset($rule_data['custom_metadata'])) {
// Restore custom metadata
update_post_meta(
$import_results['rule_mappings'][$rule_data['temp_id']],
'_custom_rule_data',
$rule_data['custom_metadata']
);
}
}
}
// Log import completion
odcm_log_custom_event(
sprintf('Data import completed by user %d', $user_id),
[
'rules_imported' => count($imported_data['rules'] ?? []),
'import_results' => $import_results
],
null,
'success',
'data_imported'
);
});
Performance and Monitoring Hooks
Filter: odcm_performance_metrics
Add custom performance metrics.
Parameters:
$metrics(array) – Performance metrics array$context(string) – Context where metrics are being collected
Returns: Modified metrics array
Example:
add_filter('odcm_performance_metrics', function($metrics, $context) {
if ($context === 'rule_evaluation') {
// Add custom timing metrics
$metrics['external_api_calls'] = $this->get_api_call_count();
$metrics['database_queries'] = $this->get_db_query_count();
$metrics['memory_peak'] = memory_get_peak_usage(true);
}
return $metrics;
}, 10, 2);
Action: odcm_performance_alert
Fired when performance thresholds are exceeded.
Parameters:
$alert_type(string) – Type of performance alert$metrics(array) – Performance metrics that triggered the alert$thresholds(array) – Configured performance thresholds
Example:
add_action('odcm_performance_alert', function($alert_type, $metrics, $thresholds) {
if ($alert_type === 'memory_usage_critical') {
// Emergency cleanup procedures
$this->emergency_cache_cleanup();
// Alert administrators
$this->send_admin_alert([
'type' => 'critical_memory_usage',
'current_usage' => $metrics['memory_usage'],
'threshold' => $thresholds['memory_critical'],
'timestamp' => current_time('mysql')
]);
}
});
Testing and Development Hooks
Filter: odcm_test_mode_enabled
Control test mode behavior for development.
Parameters:
$enabled(bool) – Whether test mode is enabled$context(string) – Context where test mode is being checked
Returns: Boolean indicating if test mode is enabled
Example:
add_filter('odcm_test_mode_enabled', function($enabled, $context) {
// Enable test mode for staging environments
if (defined('WP_ENV') && WP_ENV === 'staging') {
return true;
}
// Enable for specific user roles during development
if ($context === 'rule_evaluation' && current_user_can('develop_automations')) {
return true;
}
return $enabled;
}, 10, 2);
Action: odcm_test_data_reset
Fired when test data is being reset.
Parameters:
$reset_scope(string) – Scope of data reset (logs, rules, settings)$user_id(int) – User performing the reset
Example:
add_action('odcm_test_data_reset', function($reset_scope, $user_id) {
if ($reset_scope === 'all' || $reset_scope === 'custom_data') {
// Clean up custom test data
delete_option('custom_integration_test_data');
// Reset external service connections in test mode
$this->reset_test_service_connections();
odcm_log_custom_event(
'Custom test data reset completed',
['reset_by' => $user_id, 'scope' => $reset_scope],
null,
'info',
'test_data_reset'
);
}
});
Integration Examples
Complete Custom Integration
/**
* Example: Complete CRM Integration
*
* This example shows how to build a complete integration
* with an external CRM system using Order Daemon's hooks.
*/
class CRMIntegration {
public function __construct() {
// Register custom condition
add_filter('odcm_rule_components', [$this, 'register_components']);
// Add CRM data to order context
add_filter('odcm_order_context_data', [$this, 'add_crm_context'], 10, 3);
// Sync orders to CRM after completion
add_action('odcm_action_executed', [$this, 'sync_to_crm'], 10, 4);
// Handle CRM webhooks
add_filter('odcm_gateway_adapters', [$this, 'register_crm_adapter']);
// Add CRM settings
add_filter('odcm_settings_sections', [$this, 'add_settings_section']);
}
public function register_components($components) {
$components['conditions'][] = new CRMCustomerStatusCondition();
return $components;
}
public function add_crm_context($context_data, $order, $trigger_data) {
$customer_id = $order->get_customer_id();
if ($customer_id) {
$crm_data = $this->get_customer_from_crm($customer_id);
$context_data['crm_customer'] = $crm_data;
}
return $context_data;
}
public function sync_to_crm($action_id, $result, $order_id, $settings) {
if ($action_id === 'complete_order' && $result['success']) {
$this->sync_order_to_crm($order_id);
}
}
private function sync_order_to_crm($order_id) {
// Implementation details...
}
}
new CRMIntegration();

