I'm currently migrating data from a custom CMS over to WooCommerce. I'm able to create the products fine using the following code:
try {
$product = new WC_Product_Variable();
$product->set_name($productData["Name"]);
$product->set_description($productData["Description"]);
$product->set_price($productData["Price"]);
$product->set_sku("PW" . $productData["ID"]);
$product->set_category_ids($productData["NewCategoryIds"]);
$product->set_status($productData["OnlineStatus"]);
...
The problem I'm having though is that when I re-run my script, I get WC_Data_Exception: Invalid or duplicated SKU
.
This is odd, because when looking at the save function within the WC_Product_Variable
class, the comment says:
Save data (either create or update depending on if we are working on an existing product).
... but the save function within that class doesn't appear to do any updating.