I issued a refund and my historical profit changed. Why?
Creating a refund makes WooCommerce recalculate the cost of every line on the original order from today’s product cost. Core behavior, and not reversible.
The short answer
Because creating a refund makes WooCommerce recalculate the cost of every line on the original order, using each product’s cost as it is today—not the cost that was recorded when the sale happened.
If your buying price changed in the meantime, the stored history changes with it. This is WooCommerce core behavior, it applies to any plugin reading that field, and there is no setting to switch it off.
What WooCommerce actually does
At the end of wc_create_refund(), once the refund is saved, the core does this to the parent
order:
if ( ...->feature_is_enabled() && $order->has_cogs() ) {
$order->calculate_cogs_total_value();
}
$order->save();
and recalculating the order total walks every line item, calling calculate_cogs_value(),
which reads the product’s current cost. Saving the order then writes all of those lines back.
So a refund of one item rewrites the recorded cost of every item on that order. The Recalculate button in the order editor does the same, because it runs the same calculation. And if the product’s cost has been cleared in the meantime, the recalculation produces zero—which, as described in cost of zero and no cost, deletes the value instead of storing it. The original cost is then gone for good.
What to do about it
- Change costs, do not clear them. Emptying a cost field is the one move that can turn a refund into permanent data loss on that order.
- Export the CSV at the end of each month. It takes ten seconds and gives you a record of what the month looked like when it closed. This is the only defense that does not depend on the core changing its behavior.
- Expect small drifts on refunded orders and know where they come from, rather than suspecting the report.
How Merchgain reports it
Merchgain reports what is in the database. It does not keep a second, private copy of your cost history, and it does not write anything to the order—so it cannot protect you from this, and it will not pretend the drift is not there.
That is also why the report has a CSV export: for a store that issues refunds, a monthly export is the difference between having a cost history and trusting that nothing rewrote it.
Related answers
Doesn't match what you see in your store? Email us—we read every message. contact@merchgain.com