Skip to content

Load-test WooCommerce checkout with k6 before Black Friday

Run a realistic k6 load test against your WooCommerce checkout weeks before a big sale, using the Store API to add items, open the cart and place test orders. You will size the test from last year's busiest hour, watch the server while it runs, and get a clear pass or fail.

If you run a WooCommerce store and a big sale is coming, you can find out now whether checkout holds up before the day itself. A fast homepage under load proves little, because a page cache serves it without running PHP. Cart and checkout skip the cache, so every shopper who adds an item makes the server do real work. The test that counts is a k6 script (k6 is Grafana’s free, open-source load-testing tool) that walks the whole path from product page to placed order. You run it against a staging copy with a test payment method, ramp it to your expected peak, and watch the server while it runs.

What you’ll accomplish

  • A k6 script that shops like a real customer and places test orders through the WooCommerce Store API.
  • A target load worked out from last year’s busiest hour.
  • A ramp that holds that target for 15 minutes, then pushes 1.5 times past it.
  • A live view of PHP workers, MySQL and CPU, so you see which runs out first.
  • A repeatable pass or fail, with the test orders cleaned up afterwards.

Prerequisites

  • k6 1.0 or newer on a machine that is not the web server. Running k6 on the server steals CPU from the site you are measuring.
  • A staging copy of the store on the same size of server as production, with the same theme, plugins and PHP settings. A smaller staging server gives smaller numbers, and you cannot multiply your way back to production.
  • WooCommerce 9.3 or newer. The script uses the Nonce header. Versions before 9.3 also accepted the older X-WC-Store-API-Nonce name; newer ones read only Nonce.
  • Guest checkout allowed under WooCommerce → Settings → Accounts & Privacy, so test shoppers can order without an account.
  • A test payment method. Enable Check payments (its internal ID is cheque) or Cash on delivery (cod) on staging. These create orders without calling any payment provider.
  • One simple test product with Track stock quantity turned off on its Inventory tab, so test orders cannot sell it out. It also needs a shipping method that covers the script’s Quebec address, such as a flat rate.
  • SSH access to the server, with root or sudo for the PHP and MySQL checks, and WP-CLI (the WordPress command-line tool) for cleanup.
  • Outgoing email turned off on staging, or caught by a mail-catching plugin. Each test order sends two emails.

How it works

The homepage and product pages can come from a page cache, which returns a stored copy in milliseconds without running PHP. Once a shopper adds an item, WooCommerce sets a session cookie, and caching plugins and CDNs (content delivery networks, such as Cloudflare) skip the cache for that shopper. The cart page, the checkout page and the order itself all run full PHP and many database queries.

The script drives that path through the Store API, the REST interface the block cart and checkout use in a real browser. Three endpoints do the work: /wp-json/wc/store/v1/cart to read the cart, /wp-json/wc/store/v1/cart/add-item to add a product, and /wp-json/wc/store/v1/checkout to place the order. Every Store API response carries a fresh Nonce header, a short-lived token that proves the request came from this session. The script copies it from each response into the next write request, as the browser does. k6 keeps cookies per virtual user and empties the jar at the start of each loop, so every loop behaves like a new visitor.

Each virtual user (VU) is a simulated shopper running the script in a loop, with pauses between steps like a person. The ramp profile raises the number of VUs in stages.

Chart of virtual users over 35 minutes: ramp to 20 VUs by minute 7, hold until minute 22 while watching PHP workers and MySQL, push to 30 VUs until minute 32, then ramp down. A dashed red line marks where k6 stops early if errors pass 5%. Pass condition: place-order p(95) under 3000 ms and errors under 1%.

The 15-minute hold shows whether the store copes with your target, and the push to 1.5 times shows the room left above it. Thresholds are the pass-or-fail rules k6 checks at the end, such as “95% of order requests finish in under 3 seconds”.

Step-by-step

1. Work out your target load. You need two numbers from last year. The first is your busiest hour for orders, from Analytics → Orders with a custom date range covering only that day and the chart interval set to By hour. The second is how many shoppers who added to cart went on to order, from your analytics tool (in Google Analytics 4, purchases divided by add-to-cart events). Then apply these two lines:

  • Journeys per hour = busiest-hour orders ÷ cart-to-order ratio × growth factor.
  • Target VUs = journeys per hour ÷ 3,600 × average journey time in seconds.

The second line is Little’s law: the number of shoppers in the store at once equals the rate they arrive times how long each one stays. You measure the journey time in step 4.

Worked example, with invented numbers: 230 orders in the busiest hour, a 30% cart-to-order ratio and a growth factor of 2 give about 1,530 journeys per hour, or 0.43 per second. With a 47-second journey, the target is 0.43 × 47 ≈ 20 VUs. A factor of 2 covers a year of growth plus a promotion that lands better than planned; use more if you expect more.

2. Tell your firewall and CDN about the test. All VUs come from one IP address. A WAF (web application firewall) or bot protection will soon block them and fill your results with errors no real shopper gets. If Cloudflare sits in front of staging, add a WAF custom rule that matches your load-generator IP with the Skip action, and remove it when you finish. Do the same in any server firewall or security plugin that rate-limits by IP, including Store API rate limiting if the site turns it on through the woocommerce_store_api_rate_limit_options filter.

3. Write the script. Save this as checkout-test.js. Change the cart and checkout paths if yours differ, for example /panier/ on a French store.

import http from 'k6/http';
import { check, sleep } from 'k6';

const BASE = __ENV.BASE_URL;
const PRODUCT_ID = Number(__ENV.PRODUCT_ID);
const PRODUCT_PATH = __ENV.PRODUCT_PATH || '/shop/';
const CART_PATH = __ENV.CART_PATH || '/cart/';
const CHECKOUT_PATH = __ENV.CHECKOUT_PATH || '/checkout/';
const TARGET = Number(__ENV.TARGET_VUS || 20);
const PEAK = Math.round(TARGET * Number(__ENV.PEAK_FACTOR || 1.5));
const ORDER_RATIO = Number(__ENV.ORDER_RATIO || 0.3);
const PAYMENT = __ENV.PAYMENT_METHOD || 'cheque';

export const options = {
  stages: [
    { duration: '2m', target: Math.ceil(TARGET / 4) },
    { duration: '5m', target: TARGET },
    { duration: '15m', target: TARGET },
    { duration: '5m', target: PEAK },
    { duration: '5m', target: PEAK },
    { duration: '3m', target: 0 },
  ],
  thresholds: {
    http_req_failed: [
      { threshold: 'rate<0.01' },
      { threshold: 'rate<0.05', abortOnFail: true, delayAbortEval: '1m' },
    ],
    'http_req_duration{name:add-item}': ['p(95)<1000'],
    'http_req_duration{name:cart-page}': ['p(95)<1500'],
    'http_req_duration{name:checkout-page}': ['p(95)<1500'],
    'http_req_duration{name:place-order}': ['p(95)<3000'],
    checks: ['rate>0.99'],
  },
};

function writeHeaders(nonce) {
  return { 'Content-Type': 'application/json', Nonce: nonce };
}

export default function () {
  // Browse: pages your cache should serve
  http.get(`${BASE}/`, { tags: { name: 'home' } });
  sleep(3);
  http.get(`${BASE}${PRODUCT_PATH}`, { tags: { name: 'product' } });
  sleep(5);

  // Read the cart once to get a Store API nonce
  let res = http.get(`${BASE}/wp-json/wc/store/v1/cart`, { tags: { name: 'cart-api' } });
  let nonce = res.headers['Nonce'];

  res = http.post(
    `${BASE}/wp-json/wc/store/v1/cart/add-item`,
    JSON.stringify({ id: PRODUCT_ID, quantity: 1 }),
    { headers: writeHeaders(nonce), tags: { name: 'add-item' } }
  );
  check(res, { 'item added': (r) => r.status === 201 });
  nonce = res.headers['Nonce'] || nonce;
  sleep(5);

  // Cart and checkout pages: full PHP renders, never cached
  res = http.get(`${BASE}${CART_PATH}`, { tags: { name: 'cart-page' } });
  check(res, { 'cart page 200': (r) => r.status === 200 });
  sleep(8);
  res = http.get(`${BASE}${CHECKOUT_PATH}`, { tags: { name: 'checkout-page' } });
  check(res, { 'checkout page 200': (r) => r.status === 200 });
  sleep(20);

  // Only some shoppers buy
  if (Math.random() >= ORDER_RATIO) {
    return;
  }

  const address = {
    first_name: 'Load',
    last_name: `Test${__VU}`,
    address_1: '100 Test Street',
    city: 'Montreal',
    state: 'QC',
    postcode: 'H2X 1Y4',
    country: 'CA',
    phone: '5145550100',
  };
  res = http.post(
    `${BASE}/wp-json/wc/store/v1/checkout`,
    JSON.stringify({
      billing_address: Object.assign({ email: `loadtest+${__VU}-${__ITER}@example.com` }, address),
      shipping_address: address,
      payment_method: PAYMENT,
    }),
    { headers: writeHeaders(nonce), tags: { name: 'place-order' } }
  );
  check(res, { 'order placed': (r) => r.status === 200 && r.json('order_id') > 0 });
  sleep(5);
}

The name tags let each threshold judge one kind of request. ORDER_RATIO is your cart-to-order ratio, so orders per hour land where step 1 predicts. The first http_req_failed rule is the pass mark; the second stops the run early if the error rate since the start passes 5%.

4. Run a one-shopper smoke test. A smoke test is a short, gentle run that proves the script works. A --duration given on the command line replaces the script’s stages, so this runs one shopper for three minutes.

k6 run --vus 1 --duration 3m \
  -e BASE_URL=https://staging.example.com \
  -e PRODUCT_ID=123 -e PRODUCT_PATH=/product/test-hoodie/ \
  -e ORDER_RATIO=1 \
  checkout-test.js

Expected: every check shows ✓, http_req_failed is 0.00%, and a few test orders appear under WooCommerce → Orders with the status On hold. Use the iteration_duration average as the journey time in step 1. Every smoke-test shopper buys, so it runs a few seconds longer than a typical journey, which errs on the safe side.

Example output (excerpt):

    iteration_duration.................: avg=47.1s    min=46.6s    med=47s      max=47.9s    p(90)=47.6s    p(95)=47.8s
    iterations.........................: 4      0.021263/s

If item added fails with a 401 status, the Nonce header is missing; with 403, the nonce is invalid, usually because a cache served the cart response. If order placed fails, run k6 run --vus 1 --duration 1m --http-debug=full ... once and read the JSON error in the checkout response. It names the missing field or the unavailable payment method.

5. Start watching the server. Open three SSH sessions to the web server before the real run. The first watches PHP-FPM, the process manager that runs PHP workers, through its status page (see our PHP-FPM status page article to enable it). Use your pool’s pm.status_path in place of /fpm-status.

watch -n 5 'curl -s http://127.0.0.1/fpm-status | grep -E "listen queue|active processes|max children reached"'

Example output:

listen queue:         0
max listen queue:     3
listen queue len:     511
active processes:     14
max active processes: 20
max children reached: 0

listen queue counts requests waiting for a free PHP worker (listen queue len is only the size of that queue). On LiteSpeed with LSAPI (its own PHP handler, which has no status page), count PHP processes instead with watch -n 5 'ps -C lsphp --no-headers | wc -l' and compare with the PHP external app’s Max Connections.

The second session watches MySQL.

mysqladmin extended-status -i 5 | grep -E 'Threads_running|Slow_queries'

Example output:

| Slow_queries                                  | 7        |
| Threads_running                               | 4        |

The third runs vmstat 5 for CPU. The r column is how many processes want a CPU, and id is the percentage of CPU sitting idle.

6. Run the full test. Set TARGET_VUS to the number from step 1.

k6 run \
  -e BASE_URL=https://staging.example.com \
  -e PRODUCT_ID=123 -e PRODUCT_PATH=/product/test-hoodie/ \
  -e TARGET_VUS=20 \
  --out json=results.json --summary-export summary.json \
  checkout-test.js

The run takes 35 minutes. --out json writes every request with a timestamp, so you can line up a slow spell with the server’s numbers, and --summary-export saves the final numbers for comparing runs. To stop early, press Ctrl+C once; k6 stops cleanly and still prints the summary.

While it runs, write down the minute when anything changes: listen queue staying above 0, max children reached going up, id in vmstat falling under 25, or Threads_running staying above your CPU core count. The first of these to happen is your bottleneck.

7. Read the summary. Start with the THRESHOLDS block. Each rule shows ✓ or ✗ with the measured value.

Example output (excerpt):

  █ THRESHOLDS

    checks
    ✓ 'rate>0.99' rate=99.46%

    http_req_duration{name:add-item}
    ✓ 'p(95)<1000' p(95)=612.4ms

    http_req_duration{name:cart-page}
    ✓ 'p(95)<1500' p(95)=903.77ms

    http_req_duration{name:checkout-page}
    ✓ 'p(95)<1500' p(95)=1.12s

    http_req_duration{name:place-order}
    ✗ 'p(95)<3000' p(95)=4.21s

    http_req_failed
    ✓ 'rate<0.01' rate=0.28%
    ✓ 'rate<0.05' rate=0.28%


  █ TOTAL RESULTS

    checks_total.......................: 2974    1.416393/s
    checks_succeeded...................: 99.46%  2958 out of 2974
    checks_failed......................: 0.54%   16 out of 2974

    ✓ item added
    ✓ cart page 200
    ✓ checkout page 200
    ✗ order placed
      ↳  94% — ✓ 252 / ✗ 16

    HTTP
    http_req_duration..................: avg=486.3ms min=41.02ms med=298.51ms max=9.87s p(90)=1.02s   p(95)=1.64s
    http_req_failed....................: 0.28%  16 out of 5680
    http_reqs..........................: 5680   2.705121/s

    EXECUTION
    iteration_duration.................: avg=46.2s   min=41.3s   med=44.9s    max=1m2s  p(90)=51.7s   p(95)=54.4s
    iterations.........................: 902    0.429584/s
    vus................................: 2      min=1        max=30
    vus_max............................: 30     min=30       max=30

ERRO[2102] thresholds on metrics 'http_req_duration{name:place-order}' have been crossed

Here the store copes with browsing and the cart, but the slowest 5% of orders take over 4 seconds and 16 orders failed. p(95) means 95% of those requests were faster than this value. When a threshold fails, k6 prints that ERRO line and exits with code 99. Thresholds cover the whole run, including the push, so your notes from step 6 tell you which stage the slowdown started in. To judge the target stage on its own, rerun with -e PEAK_FACTOR=1.

8. Clean up. On staging, the cleanest reset is to restore the database you saved with wp db export before the test. To remove only the test orders, delete the on-hold orders created since the test started. Replace the date with your start time, in the store’s time zone. Check payments leave orders On hold; with Cash on delivery, use --status=processing instead.

for id in $(wp wc shop_order list --after=2026-11-02T09:00:00 --status=on-hold --field=id --per_page=100 --user=1); do
  wp wc shop_order delete "$id" --force=true --user=1
done

Expected: one Success: Deleted shop_order 4127. line per order. The list returns at most 100 orders, so repeat the loop until it prints nothing. Then remove the WAF skip rule from step 2.

Validate it works

The test passes when all of these hold on the same run:

  • Every line in THRESHOLDS shows ✓ and k6 exits with code 0 (echo $? right after the run prints 0).
  • During the 15-minute hold, listen queue stayed at 0 apart from brief blips, and max children reached did not rise.
  • During the hold, vmstat showed id above 25 and MySQL Threads_running stayed below your core count.
  • The number of test orders in WooCommerce equals the ✓ count on order placed. A gap means orders failed silently or were created twice.

After any fix, rerun with the same settings and compare the two summary.json files.

Troubleshooting

Errors climb within the first minute, all from one kind of request. Look at the status codes in results.json. A 403 or 429 usually comes from your WAF, CDN or a security plugin blocking the load-generator IP; recheck step 2. A 508 on a cPanel server with CloudLinux means the account hit its LVE (lightweight virtual environment) limit on entry processes, the number of requests one account may run at once. That limit then caps checkout for real shoppers too, so raise it before the sale.

The cart page is fast and shows as a cache hit. The test is measuring the wrong thing, and real shoppers may see someone else’s cart. Exclude the cart, checkout and account pages from page caching, and make the CDN skip the cache when WooCommerce cart cookies are present, as covered in our WooCommerce cache bypass cookies article.

Only place-order is slow, even at low load. That is a single-shopper problem, not a capacity problem. Work through WooCommerce slow checkout: find the slow step first, then come back and load-test.

The test passes on staging, but last year’s sale still produced 504 errors. Staging may not match production, or real traffic hit pages the script skips. Compare server sizes and PHP settings. If checkout times out under real load, the checkout 504 under load runbook walks through the bottleneck.

When this is the wrong approach

A production load test with real checkout is risky. A test payment method enabled there is visible to real customers, and test orders pollute your sales reports. On production, run the script with -e ORDER_RATIO=0 so VUs stop at the checkout page, and keep the full order test for staging.

Do not point load at a payment provider, even its sandbox: providers rate-limit sandboxes, and some forbid load testing in their terms. The same goes for live shipping-rate, tax or fraud services. Use a flat rate or test mode on staging, and remember that real checkout will be slower by whatever they add. k6 also skips images, CSS and third-party scripts, since it only requests the URLs you write.

This script models one product and one path. If your sale traffic leans on search, filters or logged-in customers, add those requests, or the test will flatter you. For a steady arrival rate instead of a fixed number of shoppers, the k6 documentation covers the ramping-arrival-rate executor. The WooCommerce Store API reference lists every endpoint and field the script uses.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.