3.3 WP-CLI Command Reference

The Order Daemon for WooCommerce includes comprehensive WP-CLI support, providing powerful command-line tools for managing completion rules and audit logs. These commands are particularly valuable for developers, system administrators, and power users who prefer terminal-based workflows or need to automate plugin management tasks.

Note: The WP-CLI interface is a premium feature and requires a valid license to access all functionality.

Prerequisites

Before using the Order Daemon WP-CLI commands, ensure:

  1. WP-CLI is installed on your server or development environment
  2. Order Daemon for WooCommerce is installed and activated
  3. Premium license is active and validated
  4. You have appropriate WordPress user permissions for the operations you want to perform
  5. You’re running commands from your WordPress root directory

Available Commands

The plugin provides two main command groups:

  • wp odcm rule – Manage completion rules
  • wp odcm log – Manage and view audit logs

Rule Management Commands

wp odcm rule list

Displays all completion rules with their current status and priority.

Usage:

wp odcm rule list [--format=<format>]

Options:

  • --format=<format> – Output format (default: table)
  • Available formats: table, json, csv, yaml

Examples:

# Display all rules in a table
wp odcm rule list
  
# Export rules as JSON
wp odcm rule list --format=json
  
# Export rules as CSV for spreadsheet analysis
wp odcm rule list --format=csv > rules.csv

Sample Output:

+----+--------------------------------+--------+----------+
| id | title                          | status | priority |
+----+--------------------------------+--------+----------+
| 15 | Complete Virtual Products      | publish| 10       |
| 23 | Complete Digital Downloads     | draft  | 20       |
| 31 | Complete Orders Over $100      | publish| 30       |
+----+--------------------------------+--------+----------+

wp odcm rule activate

Activates a specific completion rule by setting its status to ‘publish’.

Usage:

wp odcm rule activate <rule_id>

Parameters:

  • <rule_id> – The ID of the rule to activate (required)

Examples:

# Activate rule with ID 23
wp odcm rule activate 23

Success Response:

Success: Rule 23 has been activated.

wp odcm rule deactivate

Deactivates a specific completion rule by setting its status to ‘draft’.

Usage:

wp odcm rule deactivate <rule_id>

Parameters:

  • <rule_id> – The ID of the rule to deactivate (required)

Examples:

# Deactivate rule with ID 15
wp odcm rule deactivate 15

Success Response:

Success: Rule 15 has been deactivated.

Log Management Commands

wp odcm log list

Displays audit log entries with powerful filtering and analysis capabilities.

Usage:

wp odcm log list [--limit=<number>] [--offset=<number>] [--order-id=<id>] [--status=<status>] [--type=<type>] [--since=<date>] [--until=<date>] [--date-range=<range>] [--source=<source>] [--advanced-filters] [--orderby=<field>] [--order=<direction>] [--format=<format>]

Basic Options:

  • --limit=<number> – Maximum entries to display (default: 20)
  • --offset=<number> – Number of entries to skip (default: 0)
  • --order-id=<id> – Filter by WooCommerce order ID
  • --orderby=<field> – Sort by field (default: timestamp)
  • Available fields: log_id, timestamp, order_id, event_type, status
  • --order=<direction> – Sort direction: ASC or DESC (default: DESC)
  • --format=<format> – Output format (default: table)
  • Available formats: table, json, csv, yaml

Advanced Filtering Options:

  • --status=<status> – Filter by status (success, error, warning, info, notice, etc.)
  • --type=<type> – Filter by event type
  • --since=<date> – Show logs after this date (YYYY-MM-DD)
  • --until=<date> – Show logs before this date (YYYY-MM-DD)
  • --date-range=<range> – Filter by date range in format “YYYY-MM-DD,YYYY-MM-DD”
  • --source=<source> – Filter logs by source (manual, scheduled, webhook, etc.) (Future Development)
  • --advanced-filters – Enable advanced filtering capabilities (Future Development)

Examples:

# Basic usage - show recent 50 log entries
wp odcm log list --limit=50
  
# Show all errors from the last week
wp odcm log list --status=error --since=2025-01-12
  
# Show logs for a specific order
wp odcm log list --order-id=1234
  
# Advanced filtering with date range
wp odcm log list --date-range="2025-01-01,2025-01-31" --advanced-filters
  
# Export logs as JSON for analysis
wp odcm log list --format=json --limit=100 > logs.json
  
# Show successful completions sorted by order ID
wp odcm log list --status=success --orderby=order_id --order=ASC

Sample Output:

+----+---------------------+----------+------------------+--------+----------------------------------------+
| id | timestamp           | order_id | type             | status | summary                                |
+----+---------------------+----------+------------------+--------+----------------------------------------+
| 156| 2025-01-19 14:23:45 | 789      | order_completed  | success| Order #789 completed successfully     |
| 155| 2025-01-19 14:20:12 | 788      | rule_matched     | info   | Order #788 matched rule: Virtual Auto |
| 154| 2025-01-19 14:15:33 | 787      | invalid_order    | error  | Order #787 could not be loaded        |
+----+---------------------+----------+------------------+--------+----------------------------------------+

Note: Advanced log analysis features with statistical breakdowns are planned for future development.

wp odcm log view

Displays detailed information about specific log entries with full context.

Usage:

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

Options:

  • --id=<log_id> – Display a specific log entry by ID
  • --order-id=<id> – Filter by WooCommerce order ID
  • --status=<status> – Filter by status
  • --type=<type> – Filter by event type
  • --since=<date> – Show logs after this date (YYYY-MM-DD)
  • --until=<date> – Show logs before this date (YYYY-MM-DD)
  • --limit=<number> – Maximum entries to display (default: 1)
  • --format=<format> – Output format (default: table)

Examples:

# View details of log entry 456
wp odcm log view --id=456
  
# View the most recent error
wp odcm log view --status=error
  
# View logs for order 789 in JSON format
wp odcm log view --order-id=789 --format=json

Sample Output:

Log ID: 456
Timestamp: 2025-01-19 14:23:45
Order ID: 789
Type: order_completed
Status: success
Summary: Order #789 completed successfully
Details:
{
  "rule_id": 15,
  "rule_name": "Complete Virtual Products",
  "conditions_met": ["product_type_virtual"],
  "processing_time_ms": 125,
  "trigger": "woocommerce_order_status_processing"
}

wp odcm log export

Exports log entries to files in various formats for analysis and archival.

Usage:

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

Options:

  • --output=<file> – Write to file instead of stdout
  • --limit=<number> – Maximum entries to export (default: 100)
  • --offset=<number> – Number of entries to skip (default: 0)
  • --format=<format> – Export format (default: json)
  • Available formats: json, csv, yaml, jsonl (JSON Lines)
  • All filtering options from log list are also available

Examples:

# Export last 500 logs to JSON file
wp odcm log export --limit=500 --output=audit-logs.json
  
# Export errors as CSV for spreadsheet analysis
wp odcm log export --status=error --format=csv --output=errors.csv
  
# Export logs for specific date range as JSON Lines
wp odcm log export --since=2025-01-01 --until=2025-01-19 --format=jsonl --output=january-logs.jsonl
  
# Stream logs to another command for processing
wp odcm log export --format=json | jq '.[] | select(.status == "error")'

wp odcm log bulk-delete

Bulk delete log entries based on criteria with safety confirmations.

Usage:

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

Options:

  • --status=<status> – Delete logs with specific status (error, warning, success, info)
  • --type=<type> – Delete logs of specific event type
  • --before=<date> – Delete logs created before this date (YYYY-MM-DD)
  • --after=<date> – Delete logs created after this date (YYYY-MM-DD)
  • --order-id=<id> – Delete logs related to specific order ID
  • --limit=<number> – Maximum number of logs to delete in one operation (default: 1000)
  • --dry-run – Show what would be deleted without actually deleting
  • --yes – Skip confirmation prompt

Examples:

# Delete all error logs (with confirmation)
wp odcm log bulk-delete --status=error
  
# Delete logs older than 30 days without confirmation
wp odcm log bulk-delete --before="2024-12-01" --yes
  
# Dry run to see what would be deleted
wp odcm log bulk-delete --status=error --dry-run
  
# Delete logs for specific order
wp odcm log bulk-delete --order-id=123 --yes

Sample Output:

=== BULK DELETE OPERATION ===
  
Found 150 logs matching criteria
Will delete 150 logs (limited by --limit=1000)
Are you sure you want to delete 150 logs with status 'error'? [y/n] y
  
✅ Deleted 150 log entries
Logs: 150 → 0 (150 deleted)

wp odcm log clear

Legacy command for clearing logs. Use bulk-delete for more advanced options.

Usage:

wp odcm log clear [--type=<type>] [--before=<date>] [--yes]

Options:

  • --type=<type> – Clear only logs of a specific type
  • --before=<date> – Clear logs created before this date (YYYY-MM-DD)
  • --yes – Skip confirmation prompt

Examples:

# Clear all logs (with confirmation)
wp odcm log clear
  
# Clear all error logs without confirmation
wp odcm log clear --type=error --yes
  
# Clear logs older than 3 months
wp odcm log clear --before=2024-10-19 --yes

wp odcm log generate-sample

Generates sample log entries for testing and development purposes.

Usage:

wp odcm log generate-sample [--count=<number>]

Options:

  • --count=<number> – Number of sample entries to generate (default: 15, max: 50)

Examples:

# Generate 15 sample log entries
wp odcm log generate-sample
  
# Generate 30 sample entries for testing
wp odcm log generate-sample --count=30

Note: This is a developer tool and only works when WP_DEBUG is enabled.

Practical Use Cases

Automated Rule Management

#!/bin/bash
# Maintenance mode script
  
echo "Entering maintenance mode..."
  
# Backup current rule states
wp odcm rule list --format=json > rule-backup.json
  
# Deactivate all rules
for id in $(wp odcm rule list --format=csv --fields=id,status | grep publish | cut -d, -f1); do
wp odcm rule deactivate $id
echo "Deactivated rule $id"
done
  
# Perform maintenance tasks here
echo "Performing maintenance..."
  
# Reactivate rules from backup
echo "Reactivating rules..."
wp odcm rule activate 15
wp odcm rule activate 31
  
echo "Maintenance complete!"

Log Monitoring and Alerts

#!/bin/bash
# Error monitoring script (run via cron every 15 minutes)
  
ERRORS=$(wp odcm log list --status=error --since=$(date -d '15 minutes ago' +%Y-%m-%d\ %H:%M:%S) --format=count)
  
if [ "$ERRORS" -gt 0 ]; then
echo "Alert: $ERRORS order completion errors in the last 15 minutes"
# Get error details
wp odcm log list --status=error --since=$(date -d '15 minutes ago' +%Y-%m-%d\ %H:%M:%S) --format=table
# Send to monitoring system
curl -X POST "https://monitoring.example.com/alert" \
         -H "Content-Type: application/json" \
-d "{\"service\":\"order-daemon\",\"errors\":$ERRORS,\"timestamp\":\"$(date)\"}"
fi

Regular Log Maintenance

#!/bin/bash
# Weekly log maintenance script
  
ARCHIVE_DATE=$(date -d '30 days ago' +%Y-%m-%d)
ARCHIVE_FILE="order-daemon-archive-$(date +%Y%m).json"
  
echo "=== Weekly Log Maintenance ==="
  
# Export old logs before deletion
echo "Exporting logs older than 30 days..."
wp odcm log export --until=$ARCHIVE_DATE --output=$ARCHIVE_FILE --format=json
  
# Count what will be deleted
OLD_LOGS=$(wp odcm log bulk-delete --before=$ARCHIVE_DATE --dry-run | grep "Will delete" | awk '{print $3}')
  
if [ "$OLD_LOGS" -gt 0 ]; then
echo "Deleting $OLD_LOGS old log entries..."
wp odcm log bulk-delete --before=$ARCHIVE_DATE --yes
# Compress archive
gzip $ARCHIVE_FILE
echo "Archived $OLD_LOGS entries to ${ARCHIVE_FILE}.gz"
else
echo "No old logs to delete"
rm -f $ARCHIVE_FILE
fi
  
# Generate summary report
echo "=== Current Status ==="
wp odcm log list --limit=5 --format=table

Order Investigation Workflow

#!/bin/bash
# Investigate specific order issues
  
ORDER_ID=$1
  
if [ -z "$ORDER_ID" ]; then
echo "Usage: $0 <order_id>"
exit 1
fi
  
echo "=== Order $ORDER_ID Investigation ==="
  
# Check if order exists in WooCommerce
if ! wp post get $ORDER_ID --post_type=shop_order >/dev/null 2>&1; then
echo "❌ Order $ORDER_ID not found in WooCommerce"
exit 1
fi
  
# Get all logs for this order
echo "📋 All logs for order $ORDER_ID:"
wp odcm log list --order-id=$ORDER_ID --format=table
  
# Check for errors
ERROR_COUNT=$(wp odcm log list --order-id=$ORDER_ID --status=error --format=count)
if [ "$ERROR_COUNT" -gt 0 ]; then
echo "❌ Found $ERROR_COUNT errors for this order:"
wp odcm log view --order-id=$ORDER_ID --status=error
fi
  
# Check current rule status
echo "📊 Current active rules:"
wp odcm rule list --format=table
  
# Get order details from WooCommerce
echo "🛒 Order details:"
wp post get $ORDER_ID --field=post_status
wp wc order get $ORDER_ID --format=table

Performance Analysis

Note: Advanced performance analysis features are planned for future development. Currently, basic log filtering and export capabilities are available for manual analysis.

#!/bin/bash
# Basic log analysis example
  
echo "=== Basic Log Analysis ==="
  
# Export recent logs for manual analysis
WEEK_AGO=$(date -d '7 days ago' +%Y-%m-%d)
wp odcm log export --since=$WEEK_AGO --format=csv --output=recent-logs.csv
echo "📊 Recent logs exported to recent-logs.csv for analysis"
  
# Show recent error count
ERROR_COUNT=$(wp odcm log list --since=$WEEK_AGO --status=error --format=count)
echo "⚠️ Errors in last 7 days: $ERROR_COUNT"

Integration with CI/CD Pipelines

Deployment Health Check

#!/bin/bash
# Post-deployment health check
  
echo "=== Order Daemon Health Check ==="
  
# Check if plugin is active
if ! wp plugin is-active order-daemon/order-daemon.php; then
echo "❌ Order Daemon plugin is not active"
exit 1
fi
  
# Check for recent errors
RECENT_ERRORS=$(wp odcm log list --status=error --since=$(date -d '1 hour ago' +%Y-%m-%d\ %H:%M:%S) --format=count)
  
if [ "$RECENT_ERRORS" -gt 5 ]; then
echo "❌ Too many recent errors: $RECENT_ERRORS"
wp odcm log list --status=error --since=$(date -d '1 hour ago' +%Y-%m-%d\ %H:%M:%S) --limit=5
exit 1
fi
  
# Check active rules
ACTIVE_RULES=$(wp odcm rule list --format=csv | grep publish | wc -l)
if [ "$ACTIVE_RULES" -eq 0 ]; then
echo "⚠️ Warning: No active completion rules"
fi
  
echo "✅ Health check passed"
echo "   - Active rules: $ACTIVE_RULES"
echo "   - Recent errors: $RECENT_ERRORS"

Error Handling and Troubleshooting

Common Error Messages

  • “❌ Advanced filtering requires premium license” – Premium features are not available
  • “Rule with ID 999 not found” – Invalid rule ID specified
  • “No logs found matching criteria” – No logs match the specified filters
  • “Permission denied” – User lacks required WordPress capabilities

Performance Considerations

  • Log queries are optimized with proper database indexing
  • Use --limit to control result set sizes for large datasets
  • Export large datasets in chunks using --offset parameter
  • The bulk-delete command processes in batches to prevent timeouts
  • Advanced performance monitoring and analysis features are planned for future development

Security Notes

  • All commands respect WordPress user capabilities
  • Input parameters are sanitized and validated
  • Database operations use prepared statements to prevent SQL injection
  • The generate-sample command requires WP_DEBUG for security
  • Premium license validation is checked before command execution

Best Practices

  1. Regular Maintenance: Set up automated scripts for log cleanup and archival
  2. Monitoring: Implement error monitoring with appropriate alerting thresholds
  3. Backup: Always backup rule configurations before making changes
  4. Testing: Use --dry-run options when available to preview operations
  5. Documentation: Document custom scripts and automation workflows
  6. Performance: Monitor command execution times and optimize queries as needed

The WP-CLI integration makes Order Daemon for WooCommerce a powerful tool for developers and system administrators, enabling efficient management, monitoring, and automation of order completion rules and comprehensive audit trails.

Was this article helpful?

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