Merchgain
EN
Available now
Next, in this order
  • DeutschDE
  • EspañolES
  • FrançaisFR
  • ItalianoIT
  • PortuguêsPT
  • NederlandsNL

A language shows up here once its pages are actually written. Nothing on this site is machine-translated.

Install freeInstall
← All answers

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 behaviour, and not reversible.

Group
Where the data is missing
Source
R — behaviour of WooCommerce core
Code
REWRITE
Updated

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 behaviour, 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. 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 defence that does not depend on the core changing its behaviour.
  • 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 CSV export is in the free version rather than behind anything: for a shop that issues refunds, a monthly export is the difference between having a cost history and trusting that nothing rewrote it.

See this on a real report

Disagrees with what you see in your shop? Write to us — every message is read. contact@merchgain.com