Skip to content

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.

ElementDescription
TriggerA WooCommerce event that runs the rule (new_order, order_status_changed, …)
FilterA logical condition (order_total > 100, geo_scope in eu, …)
ActionAn operation to perform (send_email, add_order_note, webhook, …)
Match modeall - all filters met, any - one is enough
PriorityExecution 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.

ValueWhen fired
new_orderwoocommerce_new_order
order_status_changedwoocommerce_order_status_changed
new_customeruser_register
cart_abandoned(reserved - integration with AbandonedCartService)
product_savedsave_post_product

Fields available in filters (FilterField):

FieldSourceOperators
order_totalWC_Order::get_total()equals, gt, lt, not_equals
order_statusWC_Order::get_status()equals, in, not_in
item_countWC_Order::get_item_count()gt, lt, equals
billing_countryISO 3166-1 alpha-2equals, in, not_in
shipping_countryISO 3166-1 alpha-2 (fallback to billing)equals, in, not_in
geo_scopepl, eu, eea, non_euequals
customer_emailWC_Order::get_billing_email()equals, contains
payment_methodWC_Order::get_payment_method()equals, in
shipping_methodList of methods from the shipping line itemin, not_in
product_idList of product IDs in the orderin, not_in
categoryList of product_cat IDs from the order itemsin, not_in

The in / not_in operator accepts a comma-separated list (PL,DE,FR).

The geo_scope field returns one of four values for an order/user:

ValueScope
plPoland (PL)
euEU countries (27 member states)
eeaEEA = EU + Norway, Iceland, Liechtenstein
non_euThe 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.

TypeParameters
send_emailto (optional), subject, body, marketing (boolean enforcing consent)
send_smsDelegated to polski_pro/automation/send_sms (requires SmsNotificationService)
change_order_statusstatus, note
add_order_notenote, customer_note (boolean)
add_customer_tagtag (saves to the polski_customer_tags user_meta)
webhookurl - a POST with {subject_type, subject_id}

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.

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);

All endpoints require manage_woocommerce + the X-WP-Nonce header.

MethodPathDescription
GET/polski-pro/v1/automation/rulesList of rules
POST/polski-pro/v1/automation/rulesCreate 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-runSimulate on an order/user (order_id or user_id)
GET/polski-pro/v1/automation/logs?limit=200Audit log (max 500)
GET/polski-pro/v1/automation/schemaSchema of triggers/filters/actions

In the rule editor, provide an Order ID and click Run dry run. The engine:

  1. Evaluates the filters against the given order.
  2. Checks marketing consent.
  3. Executes the actions in dry-run mode (does not modify state) and returns the planned result.
  4. Writes an entry to the audit log with the flag dry_run = 1.
  • Indexes on enabled, trigger_type, priority, group_label - the engine fetches only rules matching the trigger.
  • recent($limit) in AutomationLogRepository is limited to 500 records per query.
  • Webhooks have a 10s timeout.