CLI & Automation Guide (Pro): WP-CLI Commands, Cron, & Best Practices

Order Daemon Docs

CLI Commands (Pro)

This page describes how to use command-line automation with Order Daemon. The guidance below shows recommended patterns, expected shapes, and best practices.

Important

CLI Commands Are Pro-Only: The Order Daemon CLI commands are exclusively available in the Pro plugin. The free Core plugin does not include any CLI functionality.

  • If you run wp help and do not see commands under odcm, ensure the Pro plugin is installed and activated.
  • All CLI commands require the Pro plugin to be active.
  • Exact command names and flags are subject to the Pro implementation.

Prerequisites

  • WP-CLI installed and working: wp --info
  • Appropriate permissions on the server to run wp as the site’s PHP user.
  • WooCommerce active (the free Core plugin requires it for most operations).
  • Order Daemon Pro plugin installed and activated (CLI commands only work with Pro)

Available Pro CLI Commands

The Order Daemon Pro plugin provides comprehensive WP-CLI commands for advanced rule management and automation.

Rule Management Commands

List Completion Rules

wp odcm rule list [--format=<format>] [--status=<status>]
  • Formats: table (default), json, csv, yaml
  • Status filters: all (default), active, inactive

Examples:

# List all rules
wp odcm rule list

# List active rules as JSON
wp odcm rule list --status=active --format=json

# Export rules as CSV for integration
wp odcm rule list --format=csv

Activate a Rule

wp odcm rule activate <rule_id> [--dry-run] [--yes]

Deactivate a Rule

wp odcm rule deactivate <rule_id> [--dry-run] [--yes]

Examples:

# Activate rule with confirmation
wp odcm rule activate 123

# Deactivate rule automatically (CI/CD friendly)
wp odcm rule deactivate 123 --yes

# Preview activation without making changes
wp odcm rule activate 123 --dry-run

Log Management Commands

List Log Entries

wp odcm log list [--limit=<number>] [--order-id=<id>] [--status=<status>] [--type=<type>] [--since=<date>] [--until=<date>] [--format=<format>]

Export Audit Logs

wp odcm log export [--format=<format>] [--limit=<limit>] [--order-id=<id>] [--status=<status>] [--type=<type>] [--since=<date>] [--until=<date>] [--output=<file>]

View Detailed Log Entry

wp odcm log view --id=<log_id> [--format=<format>]

Bulk Delete Logs

wp odcm log bulk-delete [--status=<status>] [--type=<type>] [--before=<date>] [--after=<date>] [--order-id=<id>] [--limit=<number>] [--dry-run] [--yes]

Examples:

# Export last 100 entries as JSON
wp odcm log export --format=json --limit=100

# View specific log entry
wp odcm log view --id=123

# Bulk delete error logs with confirmation
wp odcm log bulk-delete --status=error --dry-run

# Export logs for specific order
wp odcm log export --order-id=456 --format=csv --output=order-logs.csv

Health and Diagnostic Commands

System Health Check

wp odcm health check [--category=<category>] [--format=<format>] [--export=<file>] [--exit-code-on-warning] [--exit-code-on-critical]

Health Status

wp odcm health status [--format=<format>] [--exit-code-on-warning]

Examples:

# Basic health check with table output
wp odcm health check

# CI/CD ready JSON output with exit codes
wp odcm health check --format=json --exit-code-on-warning

# Check specific component category
wp odcm health check --category=api --format=table

# Export comprehensive report
wp odcm health check --export=health-report.json

Debug Commands

Analyze Why Rule Didn’t Trigger

wp odcm debug why-not --order=<order_id> [--rule=<rule_id_or_name>] [--format=<format>] [--verbose]

Test Rule Evaluation

wp odcm debug evaluate --order=<order_id> --rule=<rule_id_or_name> [--format=<format>]

Examples:

# Analyze why a specific rule didn't trigger
wp odcm debug why-not --order=123 --rule="Complete VIP Orders"

# Analyze why any rule didn't trigger for an order
wp odcm debug why-not --order=123

# Get JSON output for programmatic use
wp odcm debug why-not --order=123 --rule=5 --format=json

Configuration Commands

Export Configuration

wp odcm config export [--output=<file>] [--format=<format>] [--components=<components>] [--exclude-sensitive] [--include-meta]

Import Configuration

wp odcm config import <file> [--merge-strategy=<strategy>] [--components=<components>] [--backup-existing] [--dry-run] [--confirm-destructive]

Compare Configurations

wp odcm config diff [--local=<file>] [--components=<components>] [--format=<format>] [--show-values] [--export-diff=<file>] [--detailed]

Examples:

# Basic export
wp odcm config export

# Export only rules to YAML
wp odcm config export --components=rules --format=yaml --output=rules.yaml

# Export excluding sensitive data
wp odcm config export --exclude-sensitive --output=template.json

# Import with conflict resolution
wp odcm config import template.json --merge-strategy=update --backup-existing

# Preview changes without applying
wp odcm config import client-setup.json --dry-run

# Compare with local file
wp odcm config diff --local=backup.json

Command Reference

Use the built-in help system to explore available commands:

# List all Order Daemon commands
wp odcm --help

# Get help for a specific command
wp odcm rule --help
wp odcm log --help
wp odcm health --help
wp odcm config --help
wp odcm debug --help

Current Pro CLI Implementation

The Pro plugin currently implements these commands under the odcm namespace:

  • Rule Management: wp odcm rule list, wp odcm rule activate, wp odcm rule deactivate
  • Log Management: wp odcm log list, wp odcm log export, wp odcm log view, wp odcm log bulk-delete
  • Health Monitoring: wp odcm health check, wp odcm health status
  • Debug Tools: wp odcm debug why-not, wp odcm debug evaluate
  • Configuration: wp odcm config export, wp odcm config import, wp odcm config diff

Important: All CLI commands require the Order Daemon Pro plugin to be installed and activated. The free Core plugin does not include any CLI functionality.

For the most accurate and up-to-date command reference, use wp odcm --help after installing the Pro plugin.

Notes

  • Use --format=json for machine-readable output in scripts.
  • Commands should return non-zero exit codes on failure so scripts can detect errors.

Usage in cron/automation scripts

System cron example

Crontab: run nightly diagnostics and cleanup.

5 2 * * * cd /var/www/html && wp odcm health check --format=json >> /var/log/odcm-diag.log 2>&1
15 2 * * 0 cd /var/www/html && wp odcm log bulk-delete --before="2025-01-01" --yes >> /var/log/odcm-cleanup.log 2>&1

WP-Cron trigger from CLI

  • If your integration needs to queue background jobs, prefer WP-Cron/Action Scheduler and use CLI only as a driver or for inspections.

Idempotency and retries

  • Design commands to be idempotent. For long-running batches, store progress markers (e.g., last processed ID or date) and support interruption/resume.

Logging and observability

  • Emit structured audit events using odcm_log_event() from within command handlers so operators can find results in the Insight timeline.
  • Include correlation fields (e.g., process_id) in the extra payload to tie together batch runs and per-order operations.
  • Respect ODCM_DEBUG to emit verbose developer logs sparingly.

Security and permissions

  • WP-CLI runs as the system user and bypasses browser nonces. Still enforce capability checks conceptually: when mutating store data, validate that commands are intended for administrators.
  • Never expose secrets on the command line that could be captured in process lists or shells. Prefer environment variables for tokens used by your integration.
  • For public endpoints (webhooks) do not rely on CLI; use signatures/HMAC and rate limiting as documented elsewhere.

Troubleshooting

  • Command not found: Ensure Pro is installed and activated. Core does not register CLI commands.
  • WooCommerce inactive: Most commands will no-op or fail with an explanatory error.
  • Permissions / file ownership: wp must run as the same user that owns WordPress files (or with sufficient permissions).
  • Exit code non-zero: Inspect stdout/stderr logs; also check the Audit Log in the admin for entries emitted by command handlers.
  • Translations: If output includes untranslated keys, confirm the order-daemon text domain is loaded in the environment where wp runs.

Implementation notes (for Pro extenders)

  • Register commands with WP_CLI::add_command under the odcm namespace.
  • Use dependency guards: bail early if WooCommerce or Core plugin is inactive.
  • Structure handlers as thin wrappers that call into existing services (Core engine, diagnostics), not duplicate logic.
  • Return WP_CLI::success / WP_CLI::error consistently; support --format=json for structured outputs.
  • Emit odcm_log_event() entries for key milestones and failures; include process IDs for correlation.
  • Cover with basic tests where feasible; avoid long-running work inside single commands—delegate to batches/queues.

Was this article helpful?

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