My product genuinely costs zero, so why is it listed as missing a cost?
WooCommerce saves a cost of zero as no cost at all, so a free sample and a product with no cost entered end up as the same blank in the database.
The short answer
Because WooCommerce does not store a cost of zero. On an order line it deletes the value instead of saving a zero, and on a simple product it turns a zero into “no cost” before saving. A free sample and a product nobody has costed therefore look exactly the same in the database: no value at all.
Rather than guess which of the two it is, Merchgain always says no cost data and never cost 0. Free samples, giveaways and downloadable extras will show up on the missing-cost list, and no plugin can tell them apart from genuine gaps.
What WooCommerce actually does
When order item data is saved, the cost goes through this:
$cogs_value = (float) $cogs_value;
if ( 0.0 === $cogs_value ) {
$this->order_item_data_store->delete_metadata( $item->get_id(), '_cogs_value', '' );
} else {
$this->order_item_data_store->update_metadata( $item->get_id(), '_cogs_value', $cogs_value );
}
Zero deletes the row. And a product with no cost entered returns 0 from
get_cogs_total_value(), so both paths arrive at the same delete.
The product side gets there by another route. WC_Product::set_cogs_value() turns 0 into
null before anything is saved, and saving null deletes the stored value. So on a simple
product, zero and missing are the same too.
Variations are the exception. A variation keeps an explicit 0, because a variation with no value
of its own falls back to its parent’s cost, and a zero is the only way to say “this one really
costs nothing”. The order line it sells on still deletes that zero.
What to do about it
- Accept the listing for genuine freebies. They are on the list because the data cannot say otherwise, and a report that hid them would be inventing information.
- If the item does have a cost, enter it. A promotional mug still cost you something to buy and print; the honest number is that, not zero.
- Read coverage as “revenue with a known cost”, not as a score to get to 100%. A store where 6% of revenue comes from products that cost it nothing, such as digital downloads, will sit at 94% forever, and that is the correct answer.
How Merchgain reports it
Two sources, deliberately. The list of products with no cost is read from the products. A simple product with a cost of zero is on it, because WooCommerce saved it as no cost; a variation with an explicit zero is not. The coverage percentage is read from the order lines, where a zero is never stored, so it answers the only question that data can answer: how much of this revenue has a cost recorded against it.
The note about deliberate zeroes sits inside the missing-cost block, next to the list, so the first person who sees their free samples there gets the explanation on the same screen.
Related answers
Doesn't match what you see in your store? Email us—we read every message. contact@merchgain.com