Skip to content
← Back to activity

Public problem

WooCommerce REST API allows duplicate SKUs when SKU is passed via `meta_data`

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

I create products through the WooCommerce REST API (POST /wp-json/wc/v3/products) and pass the SKU inside meta_data as {"key": "_sku", "value": "1234567890"}. I was able to create multiple products with the same SKU. Shouldn't the duplicate SKU be rejected?

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

This was a real bug: when you send _sku inside meta_data, it bypassed WC_Product::set_sku() and went through MetaDataUtil::update() instead, so the SKU uniqueness check (wc_product_has_unique_sku()) never ran. It was fixed by PR #31168. On a current WooCommerce version, the same request now returns a 400 product_invalid_sku error on the second product with the same SKU, and only one product persists. The recommended practice anyway: send sku as the top-level field, not inside meta_data, since top-level always goes through the proper setter.

Source: https://github.com/woocommerce/woocommerce/issues/29286