How do I fill in product costs without clicking through 500 products?
WooCommerce imports costs from CSV and sets one cost on many products at once. Which route to use, and where to start so the report is useful after one evening.
The short answer
Use the product CSV import that comes with WooCommerce. Once Cost of Goods Sold is switched on, the product export and import both have a Cost of goods column. Export your products, fill in that column in a spreadsheet, and import the file back. For a group of products that cost the same, Bulk Edit in the products list sets one cost on all of them at once.
The shortcut that matters more than either: you do not need every product. Enter the cost for the products that actually sell and the report becomes useful right away. In many stores a few dozen products bring in most of the revenue.
What WooCommerce actually does
The core lets you enter the cost in five places:
- the product editor—the Cost of goods field in the General tab, one product at a time, plus a Cost field on each variation;
- Quick Edit and Bulk Edit in the products list—Bulk Edit sets the same cost on every product you select;
- the product CSV importer and exporter—a Cost of goods column, matched by ID or SKU when you import with Update existing products checked. An empty cell in that column removes the cost the product has, and the import changes nothing else;
- the REST API —
productsandvariationscarry acost_of_goods_soldobject with the defined value and the total; - the object API —
WC_Product::set_cogs_value()andget_cogs_value(), which is what any script or importer ends up calling anyway.
All of them appear only while the feature is on. With the feature off, the importer skips the cost column.
There is also a lookup column, wc_product_meta_lookup.cogs_total_value, which is NULL for a
product with no cost entered. That is how a list of products with no cost gets built without
crawling the meta table row by row.
What to do about it
Work top-down, not alphabetically. Sort your products by revenue, take the first page, and enter those costs first. Coverage climbs fastest that way, and coverage is what makes the rest of the report worth reading.
For the CSV route, export only the columns you need (ID, SKU, name and Cost of goods), fill in the costs, and import the file with Update existing products checked. Our bulk cost import page has a ready template and a WP-CLI script with a trial run.
If you script it yourself, it is one call per product:
wp eval '$p = wc_get_product( 123 ); $p->set_cogs_value( 41.50 ); $p->save();'
Every one of these routes writes to your store, so try it on a copy first and keep a database backup. It is your data and your import; none of it goes through Merchgain.
A cost entered today applies to future orders only. Orders already in the database keep whatever they recorded at the time, which for older orders means nothing at all.
How Merchgain reports it
Merchgain says how many products have no cost and lists the most recently edited ones, each linked to its product editor. That list is a working list: open, type the cost, save, and the report drops its cache right away instead of waiting out the hour. The coverage line above it says how much of the period’s revenue has no cost recorded.
Merchgain never writes a cost, and it has no bulk cost editor. A plugin that fills in cost values is no longer a plugin that only reads.
Related answers
Doesn't match what you see in your store? Email us—we read every message. contact@merchgain.com