Skip to content

Tax Rules

The Automatic tax rules module in Polski PRO assigns GTU codes, WooCommerce tax classes, categories, tags and product meta to WooCommerce products from condition and action rules you write. Rules run when a product is saved, on a daily, weekly or monthly schedule, or by hand, and every change is logged. The module is off by default.

  1. Create a rule: name, match mode (all/any), conditions, actions, triggers, priority.
  2. The engine evaluates conditions against every product and applies actions when the rule matches.
  3. Every rule application is written to the audit log (who/what/when, dry run or live).
  4. Triggers:
    • On product save - the rule runs after a product is created or updated.
    • Daily - the rule runs in the nightly cron against the entire catalog.
    • Weekly - runs once per week (WP-Cron).
    • Monthly - runs once per 30 days (WP-Cron).
    • Manual - the rule runs only when you click Run / Dry Run in the admin.

Open WooCommerce > Tax Rules and click Add rule.

Field Description
Name Human-readable label (e.g. "Books -> GTU_12").
Group (optional) Free-form label used for filtering in the list.
Enabled Toggle a rule off without deleting it.
Match mode all - every condition must match, any - at least one must match.
Triggers When the rule runs (save / daily / weekly / monthly / manual).
Priority Execution order, ascending (default 10).

Format: field | operator | value | key (last field optional).

Fields: title, sku, short_description, description, price, regular_price, stock_quantity, stock_status, category, tag, type, attribute, tax_class, meta_field, gtu_code, taxonomy.

Rules saved with the older field name jpk_v7_code are read as gtu_code.

Operators: equals, not_equals, contains, not_contains, starts_with, ends_with, gt, gte, lt, lte, in, not_in, is_empty, is_not_empty.

The taxonomy field accepts any custom taxonomy; put the taxonomy slug in key and a comma-separated list of term IDs in value:

taxonomy | in | 12,34,56 | product_brand

Examples:

title | contains | book
price | gte | 100
category | in | 42,56,78
meta_field | equals | yes | _polski_tablet

Format: action_type | value.

Action Description Example
set_gtu_code Assign a GTU code set_gtu_code | GTU_06
remove_gtu_code Remove the GTU code remove_gtu_code |
set_tax_class Set a WooCommerce tax class set_tax_class | reduced-rate
add_category / remove_category Add or remove a category add_category | 42
add_tag / remove_tag Add or remove a tag add_tag | 77
set_meta_field Set a meta field, key:value set_meta_field | _polski_custom:flag
delete_meta_field Delete a meta field delete_meta_field | _polski_custom
mark_receipt_with_nip Flag product as requiring receipt with NIP mark_receipt_with_nip | 1

The GTU code is stored in the _polski_gtu_code product meta. Rules saved with the older actions set_jpk_v7_code and remove_jpk_v7_code run as set_gtu_code and remove_gtu_code.

A product flagged with mark_receipt_with_nip (meta _polski_receipt_requires_nip = 1) makes the NIP field required at checkout whenever it is in the cart, through the polski/nip_required filter of Polski (free).

Each rule has Dry run (preview without writing) and Run now (apply to the whole catalog) actions. The Audit log tab shows the last 200 applications with timestamp, rule, product, match flag, dry-run flag and applied actions.

At the top of the rule editor the Insert helper panel lets you add condition/action lines without looking up IDs by hand:

  • Category - all product_cat terms (Select2). Buttons append category | in | <ID> or add_category | <ID>.
  • Tag - same for product_tag.
  • Tax class - list of WooCommerce tax classes. Buttons append set_tax_class | <slug> or tax_class | equals | <slug>.
  • GTU code - dropdown with GTU_01 to GTU_13. Buttons append the action set_gtu_code | <CODE> or the condition gtu_code | equals | <CODE>.

The textarea remains the source of truth - pickers only append lines.

Each rule may carry an optional group label. Groups are used only for organizing and filtering rules in the admin; they do not affect execution.

The rules list supports case-insensitive name search, status filter (enabled/disabled), trigger filter and group filter (visible only when groups exist).

The Import / export tab lets you:

  • Export all rules as a portable JSON file (format polski.tax_rules, v1) for backup or migration.
  • Import a previously exported JSON file. Imports always append rules (never replace by ID), so you can safely merge rule sets from multiple stores.

For large catalogs and automation:

Terminal window
# List rules
wp polski tax-rules list
wp polski tax-rules list --format=json
# Dry-run rule #3
wp polski tax-rules run 3 --dry-run
# Apply rule #3 with 100-item batches
wp polski tax-rules run 3 --batch-size=100
# Export rules to a file
wp polski tax-rules export --file=/tmp/rules.json
# Import rules from a file
wp polski tax-rules import /tmp/rules.json

On the standard WooCommerce products list (wp-admin/edit.php?post_type=product) the Bulk actions dropdown exposes two entries:

  • Apply tax rules - runs every enabled rule against the selected products.
  • Dry-run tax rules - reports what would change, without writing.

After execution an admin notice shows the number of products processed, rule matches, and changes applied.

The assigned GTU code (_polski_gtu_code) is read by:

  • the PDF invoice template of Polski (free), which prints the code next to the line item
  • not the Polski PRO PDF invoice: its TCPDF layout does not print GTU codes
  • the FA(3) document sent to KSeF, which carries the GTU code on each line whose product has one

The same code can also be set by hand in the product editor of Polski (free).

  • The daily cron processes the catalog in batches of 50 products. It can be switched off with run_daily = false in the polski_tax_rules option (default true); weekly and monthly runs are always scheduled.
  • The monthly schedule is an interval of 30 days.
  • wp polski tax-rules run uses batches of 50 unless you pass --batch-size.
  • The audit log is capped at 10,000 rows; older entries are trimmed automatically.
  • The engine guards against recursion: a rule will not re-trigger during its own internal product save.

Does the module set JPK_V7 codes separately from GTU codes?

Section titled "Does the module set JPK_V7 codes separately from GTU codes?"

No. There is one GTU code per product, stored in _polski_gtu_code. Old rules that used set_jpk_v7_code or the jpk_v7_code condition are read as their GTU equivalents.

How do I test a rule without changing products?

Section titled "How do I test a rule without changing products?"

Use Dry run on the rule, the Dry-run tax rules bulk action on selected products, or wp polski tax-rules run <id> --dry-run. Each reports matches and the changes it would make, and the audit log marks the entries as dry runs.

Will importing rules overwrite my existing ones?

Section titled "Will importing rules overwrite my existing ones?"

No. Imported rules are always appended to the list. The file must be an export in the polski.tax_rules format.

Can I stop the nightly run on a large catalog?

Section titled "Can I stop the nightly run on a large catalog?"

Yes. Set run_daily to false in the polski_tax_rules option, for example with wp option patch update polski_tax_rules run_daily 0, and the daily event is unscheduled. Rules with the Daily trigger then run only when started by hand.