I want to add variable product via woo commerce API. I successfully added the normal product via node js and php but need some example how to add variable product. I searched in documentation https://github.com/woothemes/woocommerce/tree/master/includes/api but couldn’t find any sample source code to add variable product. Is there any sample source code available to add variable product via woo commerce API. Even here also there is no sample source code to add variable product.
I used the Api and My code is as follow
<?php
require_once( 'lib/woocommerce-api.php' );
$client = new WC_API_Client( 'http://example.com', 'ck_xxxxxxxxxxxxxxxxxxxxxxx8a4e', 'cs_xxxxxxxxxxxxxxxxxxxxxxxd701acf41c');
// echo "<pre>"; print_r($client->index->get());
// die;
$data = [
'product' => [
'title' => 'Preremium112 Quality',
'type' => 'variable',
'regular_price' => '21.99',
'sku' => 'modrerts12344',
'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
'categories' => [
9,
14
],
'product_attribute' => [
'name' => 'case_model',
'type' => 'select',
'variation'=> 'true',
'options' => [
'Htc',
'Samsung'
]
],
'variations' => [
['regular_price' =>'12344',
'sku' => 'model_htc11234',
'attributes' => [
'name' => 'case_model',
'slug' => 'model',
'option'=> 'Htc'
]],
['regular_price' =>'12344',
'sku' => 'model_samsung11234',
'attributes' => [
'name' => 'case_model',
'slug' => 'model',
'option'=> 'Samsung'
]],
]
]
];
print_r($client->products->create($data));
The problem with above code is that product attributes are not updating