Automation Rules
The Automation Rules module runs actions (email, SMS, status change, note, customer tag, webhook) based on events in the store. You define rules in the WooCommerce > Automation Rules panel through a React SPA, and the engine executes them in response to a trigger.
Architecture
Section titled “Architecture”| Element | Description |
|---|---|
| Trigger | A WooCommerce event that runs the rule (new_order, order_status_changed, …) |
| Filter | A logical condition (order_total > 100, geo_scope in eu, …) |
| Action | An operation to perform (send_email, add_order_note, webhook, …) |
| Match mode | all - all filters met, any - one is enough |
| Priority | Execution order (lower = earlier) |
Rules are stored in the wp_polski_pro_automation_rules table. Executions (matched/skipped, dry run, action result, error) go to wp_polski_pro_automation_logs.
Triggers
Section titled “Triggers”| Value | When fired |
|---|---|
new_order | woocommerce_new_order |
order_status_changed | woocommerce_order_status_changed |
new_customer | user_register |
cart_abandoned | (reserved - integration with AbandonedCartService) |
product_saved | save_post_product |
Filters
Section titled “Filters”Fields available in filters (FilterField):
| Field | Source | Operators |
|---|---|---|
order_total | WC_Order::get_total() | equals, gt, lt, not_equals |
order_status | WC_Order::get_status() | equals, in, not_in |
item_count | WC_Order::get_item_count() | gt, lt, equals |
billing_country | ISO 3166-1 alpha-2 | equals, in, not_in |
shipping_country | ISO 3166-1 alpha-2 (fallback to billing) | equals, in, not_in |
geo_scope | pl, eu, eea, non_eu | equals |
customer_email | WC_Order::get_billing_email() | equals, contains |
payment_method | WC_Order::get_payment_method() | equals, in |
shipping_method | List of methods from the shipping line item | in, not_in |
product_id | List of product IDs in the order | in, not_in |
category | List of product_cat IDs from the order items | in, not_in |
The in / not_in operator accepts a comma-separated list (PL,DE,FR).
Geographic filters
Section titled “Geographic filters”The geo_scope field returns one of four values for an order/user:
| Value | Scope |
|---|---|
pl | Poland (PL) |
eu | EU countries (27 member states) |
eea | EEA = EU + Norway, Iceland, Liechtenstein |
non_eu | The rest of the world |
Usage example: a rule sends a different marketing email template to customers from the EU (with a GDPR note) than to those outside the EU.
Actions
Section titled “Actions”| Type | Parameters |
|---|---|
send_email | to (optional), subject, body, marketing (boolean enforcing consent) |
send_sms | Delegated to polski_pro/automation/send_sms (requires SmsNotificationService) |
change_order_status | status, note |
add_order_note | note, customer_note (boolean) |
add_customer_tag | tag (saves to the polski_customer_tags user_meta) |
webhook | url - a POST with {subject_type, subject_id} |
Marketing consent
Section titled “Marketing consent”Actions with params.marketing = true are skipped if the customer does not have valid marketing consent in polski_consent_log. The polski_pro/automation/has_marketing_consent filter lets you replace the default consent-checking logic.
Extending actions
Section titled “Extending actions”To add a custom action (e.g. integration with FreshMail/GetResponse), use the filter:
add_filter('polski_pro/automation/action', function ($override, $action, $subject, $dryRun) { if ($action->type->value === 'send_email' && ($action->params['provider'] ?? '') === 'freshmail') { if ($dryRun) { return ['dry_run' => true, 'provider' => 'freshmail']; } // ... FreshMail API call ... return ['provider' => 'freshmail', 'sent' => true]; }
return $override;}, 10, 4);REST API
Section titled “REST API”All endpoints require manage_woocommerce + the X-WP-Nonce header.
| Method | Path | Description |
|---|---|---|
| GET | /polski-pro/v1/automation/rules | List of rules |
| POST | /polski-pro/v1/automation/rules | Create a rule |
| GET | /polski-pro/v1/automation/rules/{id} | Retrieve a single rule |
| PUT | /polski-pro/v1/automation/rules/{id} | Update a rule |
| DELETE | /polski-pro/v1/automation/rules/{id} | Delete + clean up logs |
| POST | /polski-pro/v1/automation/rules/{id}/dry-run | Simulate on an order/user (order_id or user_id) |
| GET | /polski-pro/v1/automation/logs?limit=200 | Audit log (max 500) |
| GET | /polski-pro/v1/automation/schema | Schema of triggers/filters/actions |
Dry run
Section titled “Dry run”In the rule editor, provide an Order ID and click Run dry run. The engine:
- Evaluates the filters against the given order.
- Checks marketing consent.
- Executes the actions in dry-run mode (does not modify state) and returns the planned result.
- Writes an entry to the audit log with the flag
dry_run = 1.
Limits and performance
Section titled “Limits and performance”- Indexes on
enabled,trigger_type,priority,group_label- the engine fetches only rules matching the trigger. recent($limit)inAutomationLogRepositoryis limited to 500 records per query.- Webhooks have a 10s timeout.