Skip to content

WooCommerce refunds: automatic vs manual, partial amounts, tax and restock

An automatic WooCommerce refund calls the payment gateway and money actually moves; a manual one only records it. Do partial and line-item refunds correctly, restock only when you should, and reconcile against the gateway.

The WooCommerce order screen offers you two refund buttons and they do completely different things. One says “Refund via” followed by your gateway’s name: that one calls the processor’s refund API and money genuinely leaves your merchant account. The other says “Refund manually”: it writes a refund record into WooCommerce and stops there, on the assumption that you moved the money some other way. Nothing warns you if you pick the wrong one. Choose manual on a live gateway and the customer is still waiting for money that never left. Choose automatic after you already refunded from the processor’s own dashboard and you have paid them twice. This guide covers the data model behind both, line-item and amount-only partial refunds, when the restock checkbox lies to you, and how to reconcile a month of refunds against the gateway.

What you’ll accomplish

  • Tell, for any past refund, whether money actually moved through the gateway or was only recorded locally.
  • Issue a partial refund tied to specific line items, with tax refunded proportionally, so product-level reporting stays honest.
  • Decide the restock question per line item from the order data rather than from the checkbox default.
  • Refund an order whose gateway is gone, disabled, or whose transaction is too old for the processor to touch.
  • Produce a date-ranged list of refunds you can lay next to the gateway’s own export.

Prerequisites

WooCommerce 8.0 or later on WordPress 6.4+, PHP 8.1+. The refund model described here has been stable since WooCommerce 3.0, so older stores behave the same in outline; the exact admin button wording has moved around over the years.

Shell access with WP-CLI available as wp, run as the site user from the WordPress root. Everything below uses wp eval with WooCommerce’s own CRUD functions rather than raw SQL. That is deliberate: it returns the same answers on High-Performance Order Storage and on the legacy post tables, and refunds are stored differently in each. Check where you are before trusting any SQL you find elsewhere:

wp option get woocommerce_custom_orders_table_enabled
yes

You also need read access to the payment processor’s own dashboard; reconciliation is two-sided and the store is only one side of it. Note that wp eval runs as no user, which is fine for reading and for wc_create_refund() but records refunded_by as 0 unless you set a user first.

How it works

A refund is not an edit. WooCommerce never rewrites the order. It creates a separate record of type shop_order_refund whose parent is the order, carrying an amount interpreted as money going the other way, plus optional line items whose totals are negative.

Diagram of a WooCommerce order with two child refund records, one with line items and one amount-only, and the totals derived from them

That is why the order total on the screen never changes. get_total() still returns what the customer originally agreed to pay, because that is a historical fact. What changes is everything derived: get_total_refunded() sums the child refunds, get_remaining_refund_amount() subtracts that from the total, and the analytics tables record refunds as their own negative rows, which is how gross sales and net sales end up different numbers in the same report. The order status only flips to refunded when the remaining refundable amount reaches zero.

The second axis is whether money moved. wc_create_refund() takes a refund_payment flag. When it is true, WooCommerce looks up the gateway that processed the order and calls its process_refund() method, which talks to the processor over the network. When it is false, no network call happens at all and you get a local record only.

Decision diagram comparing the automatic refund path that calls the gateway API with the manual path that only writes a local record

The automatic path is only offered when the gateway plugin is still installed and enabled, the gateway declares supports( 'refunds' ), and the order carries a transaction ID the processor can act on. Miss any one and the admin screen quietly shows only the manual button. That silence causes most double-refund incidents, because nobody notices the label changed.

Step-by-step

  1. Read the order’s refund state before touching anything. You need the gateway, the transaction ID, and how much is still refundable.
wp eval '
$o = wc_get_order( 1482 );
printf( "status:%s gateway:%s txn:%s\n", $o->get_status(), $o->get_payment_method(), $o->get_transaction_id() );
printf( "total:%s refunded:%s remaining:%s\n", $o->get_total(), $o->get_total_refunded(), $o->get_remaining_refund_amount() );
'
status:processing gateway:stripe txn:ch_3Qk8vXY1a2b3c4d5
total:155.25 refunded:0 remaining:155.25

An empty txn: is the first warning sign. Without a transaction ID the processor has nothing to reference and the automatic path is off the table.

  1. Confirm the gateway can still refund. This is the check the admin screen runs before deciding which button to render.
wp eval '
$o = wc_get_order( 1482 );
$g = wc_get_payment_gateway_by_order( $o );
if ( ! $g ) { echo "no gateway object available: manual refund only\n"; exit; }
printf( "%s | enabled:%s | supports refunds:%s\n", $g->id, $g->enabled, $g->supports( "refunds" ) ? "yes" : "no" );
'
stripe | enabled:yes | supports refunds:yes
  1. List the line items and their existing stock footprint. The item IDs here are what a line-item refund keys on, and _reduced_stock tells you whether this line ever took units out of inventory.
wp eval '
$o = wc_get_order( 1482 );
foreach ( $o->get_items() as $id => $item ) {
  printf( "%d | %s | qty %s | total %s | tax %s | reduced_stock %s\n",
    $id, $item->get_name(), $item->get_quantity(), $item->get_total(),
    $item->get_total_tax(), $item->get_meta( "_reduced_stock" ) );
}
'
84 | Field Notebook | qty 2 | total 120.00 | tax 18.00 | reduced_stock 2
  1. Get the tax rate IDs for the line you are refunding. Tax is not refunded automatically in proportion; you tell WooCommerce which rate gets how much back. The keys of the total array are tax rate IDs.
wp eval '
$o = wc_get_order( 1482 );
print_r( $o->get_item( 84 )->get_taxes() );
'
Array
(
    [total] => Array
        (
            [3] => 18.00
        )
    [subtotal] => Array
        (
            [3] => 18.00
        )
)
  1. Create the refund. Refunding one of the two notebooks means half the line total and half its tax. Keep amount equal to the sum of the line refunds plus their tax, or the totals and the reports will disagree with each other forever.
wp eval '
# refund_payment true means the gateway API is called and money moves
$r = wc_create_refund( array(
  "order_id"       => 1482,
  "amount"         => "69.00",
  "reason"         => "One unit returned, RMA 7741",
  "refund_payment" => true,
  "restock_items"  => true,
  "line_items"     => array(
    84 => array(
      "qty"          => 1,
      "refund_total" => 60.00,
      "refund_tax"   => array( 3 => 9.00 ),
    ),
  ),
) );
if ( is_wp_error( $r ) ) { echo "ERROR: " . $r->get_error_message() . "\n"; exit( 1 ); }
printf( "refund %d created for %s\n", $r->get_id(), $r->get_amount() );
'
refund 1483 created for 69.00
  1. Refund shipping the same way when it is part of the return. Shipping lines are separate items with their own IDs and their own tax. A goodwill refund on shipping alone is an amount-only refund, with line_items omitted entirely.

  2. Set an acting user when the audit trail matters. wp eval has no current user, so the refund is attributed to nobody. Prefix the call and the record names a human.

wp eval '
wp_set_current_user( 4 );
$r = wc_create_refund( array( "order_id" => 1482, "amount" => "15.00", "reason" => "Shipping goodwill", "refund_payment" => true ) );
printf( "refund %d by user %d\n", $r->get_id(), $r->get_refunded_by() );
'
refund 1490 by user 4

Validate it works

Read the refunds back through the order and confirm both the arithmetic and, critically, whether each one went through the gateway.

wp eval '
$o = wc_get_order( 1482 );
foreach ( $o->get_refunds() as $r ) {
  printf( "#%d %s %8s via_gateway:%-3s by:%s %s\n",
    $r->get_id(), $r->get_date_created()->date( "Y-m-d H:i" ), $r->get_amount(),
    $r->get_refunded_payment() ? "yes" : "no", $r->get_refunded_by(), $r->get_reason() );
}
printf( "total:%s refunded:%s remaining:%s status:%s\n",
  $o->get_total(), $o->get_total_refunded(), $o->get_remaining_refund_amount(), $o->get_status() );
'
#1490 2026-08-25 14:12    15.00 via_gateway:yes by:4 Shipping goodwill
#1483 2026-08-25 14:03    69.00 via_gateway:yes by:0 One unit returned, RMA 7741
total:155.25 refunded:84.00 remaining:71.25 status:processing

Then confirm the stock side actually moved, and only once:

wp eval '
$o = wc_get_order( 1482 );
foreach ( $o->get_items() as $id => $item ) {
  printf( "%d reduced:%s restocked:%s\n", $id, $item->get_meta( "_reduced_stock" ), $item->get_meta( "_restock_refunded_items" ) );
}
$p = wc_get_product( 512 );
printf( "%s stock:%s status:%s\n", $p->get_sku(), $p->get_stock_quantity(), $p->get_stock_status() );
'
84 reduced:2 restocked:1
FN-A5-BLK stock:7 status:instock

For month-end reconciliation, pull every refund in a date range and mark which ones the gateway should also show. Paste this next to the processor’s export and the rows that appear on only one side are your work list.

wp eval '
foreach ( wc_get_orders( array( "type" => "shop_order_refund", "limit" => -1, "date_created" => ">=2026-08-01" ) ) as $r ) {
  printf( "%s\t%d\tparent:%d\t%s\t%s\n", $r->get_date_created()->date( "Y-m-d" ), $r->get_id(),
    $r->get_parent_id(), $r->get_amount(), $r->get_refunded_payment() ? "gateway" : "manual" );
}
' > /tmp/refunds-august.tsv && wc -l /tmp/refunds-august.tsv
23 /tmp/refunds-august.tsv

On a store that has not migrated to High-Performance Order Storage, wp post list --post_type=shop_order_refund --fields=ID,post_date,post_parent gives you the same skeleton. On an HPOS store that command returns nothing, because the records are no longer posts. That difference alone has convinced more than one operator that their refunds vanished.

Troubleshooting

The gateway API errored and now the order looks untouched. When process_refund() returns an error, wc_create_refund() deletes the refund it had just built and returns the error, and the restock step never runs. Locally you see an error notice and an unchanged order. But a network timeout is not the same as a rejection: the processor may have accepted the refund and failed to tell you. Always check the processor’s dashboard for that transaction before retrying. If money did move, record it as a manual refund instead, or you will refund twice.

“Invalid refund amount”. You asked for more than get_remaining_refund_amount() returns, or a rounding mismatch pushed you a cent over. Read the remaining amount first and refund exactly that when closing an order out.

The gateway is disconnected, removed, or the transaction has aged out. Processors put an age limit on API refunds; PayPal, for example, refuses refunds on transactions past its refund window. Once you are outside it, or once the gateway plugin is gone and wc_get_payment_gateway_by_order() returns nothing, there is no automatic path left. Send the money by whatever means the processor and the customer support, then record a manual refund with the external reference in the reason field so the next person reconciling can trace it.

Restocking put back units that were never taken out. The reduce path and the restock path track themselves with separate item meta, _reduced_stock and _restock_refunded_items. An order that never reached a stock-reducing status still restocks happily when you tick the box, inflating inventory. Check _reduced_stock on the line before ticking, and if you find yourself chasing phantom units, the mechanics are laid out in WooCommerce overselling and stock race conditions.

Reports do not move after a refund. Amount-only refunds carry no line items, so no product is attributed and product-level reports stay exactly as they were, even though revenue reports drop. That is not a bug, it is the direct consequence of refunding an amount instead of a line. If order-level totals also look wrong, the analytics lookup tables may be stale; wp wc tool list --user=1 lists the maintenance tools available on your version, including the ones that rebuild reporting data.

When this is the wrong approach

A chargeback is not a refund. When a customer disputes through their bank, the processor pulls the funds and adds a fee, and issuing a WooCommerce refund on top of that pays them a second time. Handle disputes entirely in the processor’s dashboard and record the outcome in the order notes, not as a refund.

Correcting an order before the customer has paid is not a refund either. A pending or on-hold order can simply be edited, which avoids creating a refund record that reconciliation will later ask you to explain.

Subscriptions, deposits, and instalment plans layer their own money model on top of orders. Refunding the parent order without going through the extension that created the schedule leaves that extension’s records out of step.

Finally, if refunds are a daily, high-volume part of the business, the order screen is the wrong interface. You want a returns process with its own states, where the WooCommerce refund is the last step rather than the whole thing.

Related reading if the underlying problem is not the refund itself: why a payment gateway does not appear at checkout, and when order notification email never arrives. The reference material worth keeping open is the WooCommerce documentation for the admin workflow and the WooCommerce developer portal for the refund functions and gateway methods named above.

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