Diagnostic Shipping and tax at renewal
WooCommerce subscription renewals keep charging the old tax rate
A tax rate changes and you update it in WooCommerce. Every new order is taxed correctly from that moment. Every subscription sold before it keeps renewing with the old tax, because its tax lines were calculated once, at sign-up, and are copied forward. Here is why, and a small read-only check that compares each subscription's tax lines with your rates today.
WooCommerce's own documentation says it: for automatic renewals, taxes calculated at sign-up are applied to all renewal payments, and changing recurring tax means changing the subscription's tax lines. Run a small Python or Node.js check that reads each active subscription's tax lines, with the rate each was calculated at, and compares it with the same rate in your store today. It lists every stale or deleted rate and changes nothing.
The problem in plain words
Your store charges GST at 10%. A subscription sold today stores a tax line: GST, rate 10%, 5.00 on the products and 1.00 on the shipping. Next year the rate becomes 12% and you update it under WooCommerce, Settings, Tax. New orders are taxed at 12% straight away.
The subscription's tax line still says 10%. Its renewals are built from it, so they charge 10% too, every cycle. If you collect the tax you owe at 12%, the gap is yours to pay.
Why it happens
WooCommerce's renewal documentation is explicit for automatic renewals: "Taxes calculated at the time of sign-up are applied for all renewal payments. If you need to change recurring taxes, you need to manually change recurring tax line items for the subscription."
- A changed rate percentage reaches checkout only.
- A deleted rate leaves the old line in place on every subscription that used it.
- On stores that enter prices including tax, a rate change would move the price itself, which is a different decision; the check leaves those alone.
Each tax line remembers its rate id and the percentage it was calculated at. Comparing those two numbers with the rate table today finds every stale line without recalculating anything.
The fix, as a flow
The check loads your tax rates once, then reads every active subscription's tax lines and compares each line's stored rate_percent with the same rate id today. A rate that no longer exists is reported as gone.
Build it step by step
Give the script read access
A WooCommerce REST API key with Read permission, or an administrator's application password. Only GET requests are sent.
pip install requests
export WOO_STORE_URL="https://yourstore.com"
export WOO_CONSUMER_KEY="ck_..." # or an admin username
export WOO_CONSUMER_SECRET="cs_..." # or its application password
# Node 18 or later: fetch is built in, nothing to install.
export WOO_STORE_URL="https://yourstore.com"
export WOO_CONSUMER_KEY="ck_..." # or an admin username
export WOO_CONSUMER_SECRET="cs_..." # or its application password
Compare in one pure function
The decision takes a subscription and a map of rate id to rate, and returns the lines that differ. A rate that is missing from the map has been deleted.
def decide(sub, rates):
"""One subscription -> list of (rate_id, label, then, now). now is None when the rate was deleted."""
out = []
for line in sub.get("tax_lines") or []:
rid = line.get("rate_id")
then = float(line.get("rate_percent") or 0)
now = rates.get(rid)
if now is None:
out.append((rid, line.get("label"), then, None))
elif abs(float(now) - then) > 1e-9:
out.append((rid, line.get("label"), then, float(now)))
return out
export function decide(sub, rates) {
const out = [];
for (const line of sub.tax_lines || []) {
const then = Number(line.rate_percent || 0);
const now = rates[line.rate_id];
if (now === undefined) out.push([line.rate_id, line.label, then, null]);
else if (Math.abs(Number(now) - then) > 1e-9) out.push([line.rate_id, line.label, then, Number(now)]);
}
return out;
}
Run it after every rate change
And on a schedule. It exits with status 1 when it finds stale lines.
python3 check_renewal_tax.py
# weekly, Monday 07:00
0 7 * * 1 cd /opt/checks && python3 check_renewal_tax.py || echo "see the list above"
node check-renewal-tax.mjs
# weekly, Monday 07:00
0 7 * * 1 cd /opt/checks && node check-renewal-tax.mjs || echo "see the list above"
The check never writes: no order notes, no edits, no status changes. Changing what a customer is charged is a decision to make after reading the list, not something a script should do on its own.
The full code
The complete check in one file for each language. It reads its settings from the environment and pages through every active subscription, 100 at a time.
"""List active subscriptions whose tax lines use a rate that has since changed.
A subscription stores its tax lines with the rate they were calculated at,
and renewals copy them. Change a tax rate in WooCommerce and existing
subscribers keep being taxed at the old one. This compares each tax line's
rate_percent with the rate as it stands today. Read only: it changes nothing.
Guide: https://www.allanninal.dev/woocommerce/tax-rate-change-never-reaches-renewals/
"""
from requests.auth import HTTPBasicAuth
import os
import requests
import sys
WOO_URL = os.environ["WOO_STORE_URL"].rstrip("/")
AUTH = HTTPBasicAuth(os.environ["WOO_CONSUMER_KEY"], os.environ["WOO_CONSUMER_SECRET"])
def woo(path, **params):
r = requests.get(f"{WOO_URL}/wp-json/wc/v3/{path}", auth=AUTH, params=params, timeout=30)
r.raise_for_status()
return r.json()
def every(path, **params):
page = 1
while True:
batch = woo(path, per_page=100, page=page, **params)
yield from batch
if len(batch) < 100:
return
page += 1
def minor(amount):
"""'10.00' -> 1000. Two-decimal currencies; zero-decimal ones need their own factor."""
return round(float(amount or 0) * 100)
def renewals_per_year(sub):
per = {"day": 365, "week": 52, "month": 12, "year": 1}.get(sub.get("billing_period"), 0)
return per / max(1, int(sub.get("billing_interval") or 1))
def methods_by_instance():
"""Every shipping method instance in every zone, keyed by instance id."""
out = {}
for zone in woo("shipping/zones"):
for m in woo(f"shipping/zones/{zone['id']}/methods"):
out[str(m["instance_id"])] = {**m, "zone_id": zone["id"], "zone_name": zone["name"]}
return out
def decide(sub, rates):
"""One subscription -> list of (rate_id, label, then, now). now is None when the rate was deleted."""
out = []
for line in sub.get("tax_lines") or []:
rid = line.get("rate_id")
then = float(line.get("rate_percent") or 0)
now = rates.get(rid)
if now is None:
out.append((rid, line.get("label"), then, None))
elif abs(float(now) - then) > 1e-9:
out.append((rid, line.get("label"), then, float(now)))
return out
def main():
rates = {r["id"]: r["rate"] for r in every("taxes")}
found = 0
for sub in every("subscriptions", status="active"):
if sub.get("prices_include_tax"):
print(f"#{sub['id']}: prices include tax; a rate change moves the price itself, not compared")
continue
for rid, label, then, now in decide(sub, rates):
found += 1
if now is None:
print(f"#{sub['id']}: {label} (rate {rid}) at {then:g}% no longer exists")
else:
print(f"#{sub['id']}: {label} (rate {rid}) stored at {then:g}%, now {now:g}%")
print(f"{found} stale tax line(s) on active subscriptions.")
return 1 if found else 0
if __name__ == "__main__":
sys.exit(main())
/**
* List active subscriptions whose tax lines use a rate that has since changed.
*
* A subscription stores its tax lines with the rate they were calculated at, and
* renewals copy them. Change a tax rate and existing subscribers keep being taxed at
* the old one. This compares each tax line's rate_percent with today's rate. Read only.
*
* Guide: https://www.allanninal.dev/woocommerce/tax-rate-change-never-reaches-renewals/
*/
import { pathToFileURL } from "node:url";
const WOO_URL = (process.env.WOO_STORE_URL || "https://example.com").replace(/\/$/, "");
const AUTH = "Basic " + Buffer.from(
`${process.env.WOO_CONSUMER_KEY || "ck_dummy"}:${process.env.WOO_CONSUMER_SECRET || "cs_dummy"}`
).toString("base64");
async function woo(path, params = {}) {
const url = new URL(`${WOO_URL}/wp-json/wc/v3/${path}`);
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
const res = await fetch(url, { headers: { Authorization: AUTH } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return res.json();
}
async function* every(path, params = {}) {
for (let page = 1; ; page++) {
const batch = await woo(path, { per_page: 100, page, ...params });
yield* batch;
if (batch.length < 100) return;
}
}
/** "10.00" -> 1000. Two-decimal currencies; zero-decimal ones need their own factor. */
const minor = (amount) => Math.round(Number(amount || 0) * 100);
function renewalsPerYear(sub) {
const per = { day: 365, week: 52, month: 12, year: 1 }[sub.billing_period] || 0;
return per / Math.max(1, Number(sub.billing_interval || 1));
}
/** Every shipping method instance in every zone, keyed by instance id. */
async function methodsByInstance() {
const out = {};
for (const zone of await woo("shipping/zones")) {
for (const m of await woo(`shipping/zones/${zone.id}/methods`)) {
out[String(m.instance_id)] = { ...m, zone_id: zone.id, zone_name: zone.name };
}
}
return out;
}
const settingsOf = (method) =>
Object.fromEntries(Object.entries(method.settings || {}).map(([k, v]) => [k, (v || {}).value]));
export function decide(sub, rates) {
const out = [];
for (const line of sub.tax_lines || []) {
const then = Number(line.rate_percent || 0);
const now = rates[line.rate_id];
if (now === undefined) out.push([line.rate_id, line.label, then, null]);
else if (Math.abs(Number(now) - then) > 1e-9) out.push([line.rate_id, line.label, then, Number(now)]);
}
return out;
}
export async function run() {
const rates = {};
for await (const r of every("taxes")) rates[r.id] = r.rate;
let found = 0;
for await (const sub of every("subscriptions", { status: "active" })) {
if (sub.prices_include_tax) {
console.log(`#${sub.id}: prices include tax; a rate change moves the price itself, not compared`);
continue;
}
for (const [id, label, then, now] of decide(sub, rates)) {
found++;
console.log(now === null
? `#${sub.id}: ${label} (rate ${id}) at ${then}% no longer exists`
: `#${sub.id}: ${label} (rate ${id}) stored at ${then}%, now ${now}%`);
}
}
console.log(`${found} stale tax line(s) on active subscriptions.`);
return found ? 1 : 0;
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
run().then((code) => process.exit(code)).catch((err) => { console.error(err); process.exit(2); });
}
Add a test
The decision is the part most worth testing, and because it is a pure function the tests need no store and no network: they feed in plain objects and check the answer.
from check_renewal_tax import decide
def sub(*lines):
return {"tax_lines": [{"rate_id": r, "label": "GST", "rate_percent": p} for r, p in lines]}
def test_a_changed_rate_is_reported():
assert decide(sub((1, 10)), {1: "12.0000"}) == [(1, "GST", 10.0, 12.0)]
def test_an_unchanged_rate_is_not():
assert decide(sub((1, 10)), {1: "10.0000"}) == []
def test_a_deleted_rate_is_reported_as_gone():
assert decide(sub((7, 5)), {1: "10.0000"}) == [(7, "GST", 5.0, None)]
import { test } from "node:test";
import assert from "node:assert/strict";
import { decide } from "./check-renewal-tax.mjs";
const sub = (...lines) => ({ tax_lines: lines.map(([rate_id, rate_percent]) => ({ rate_id, label: "GST", rate_percent })) });
test("a changed rate is reported", () => assert.deepEqual(decide(sub([1, 10]), { 1: "12.0000" }), [[1, "GST", 10, 12]]));
test("an unchanged rate is not", () => assert.deepEqual(decide(sub([1, 10]), { 1: "10.0000" }), []));
test("a deleted rate is reported as gone", () => assert.deepEqual(decide(sub([7, 5]), { 1: "10.0000" }), [[7, "GST", 5, null]]));
Worked example
What it found
On a test store with WooCommerce Subscriptions 9.4.1 and GST at 10%, the rate was changed to 12%. The check listed every active subscription's GST line as stored at 10%, now 12%: eight lines across the subscriptions on that rate. Set back to 10%, it reported none.
A 2% rise on a 66.00 renewal (60.00 taxable) is 1.20 a renewal, 14.40 a year per subscriber.
FAQ
Does WooCommerce Subscriptions update tax when a tax rate changes?
Not for automatic renewals. WooCommerce's documentation says taxes calculated at sign-up are applied to all renewal payments, and that changing recurring tax means changing the subscription's tax line items.
What about manual renewals?
A manual renewal goes through checkout, so its tax is calculated then. The stale rate only affects automatic renewals.
My prices include tax. Why does the check skip those stores?
When prices include tax, a rate change alters how a fixed price splits between product and tax, or the price itself, depending on your settings. That is a pricing decision rather than a stale line, so the check does not report it.
Related field notes
Citations
- WooCommerce docs: the renewal process, including how taxes and the shipping method carry to automatic renewals. woocommerce.com/document/subscriptions/renewal-process
- WooCommerce docs: setting up taxes and tax rates. woocommerce.com/document/setting-up-taxes-in-woocommerce
- WooCommerce Subscriptions REST API: listing subscriptions and their shipping and tax lines. woocommerce.github.io/subscriptions-rest-api-docs
- WooCommerce REST API: shipping zones, zone methods, zone locations, taxes and settings. woocommerce.github.io/woocommerce-rest-api-docs
Recalcproof recalculates each automatic renewal's tax with WooCommerce's own tax calculation just before the card is charged, without editing the subscription, and refuses stores that enter prices including tax, for the reason above.
Did this find money you were not collecting?
If this check turned up renewals charging old rates, you can buy me a coffee. It is the best way to keep these field notes free and growing.
Buy me a coffee on Ko-fi