I want to create a new product with woocommerce api. I have a color attribute and i'd like to recognize product from sku for example codeblack.
My problem is how to do this.
While creating a product with tilte,description,sku etc it's ok. To create a product with attributes, i added 'type' => 'variable'.
Now i have attributes, i enabled variations but i cannot give value to my variation.
Here's my code
$client->products->create(
array(
'title' => 'Premium Quality',
'type' => 'variable',
'sku' => 'code',
'regular_price' => '29.98',
'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.',
'images' => array(
array(
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 0
),
array(
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
'position' => 1
)
),
'attributes' => array(
array(
'name'=>'color',
'slug'=>'color',
'position'=>'0',
'visible'=>'true',
'variation'=>'true',
'options'=>array('red','black')
)
),
'variations' => array(
array(
'sku' => 'codered',
'regular_price' => '29.98',
'attributes' => array(
array(
'name'=>'color',
'options'=>'red'
)
)
),
array(
'sku' => 'codeblack',
'regular_price' => '29.98',
'attributes' => array(
array(
'name'=>'color',
'options'=>'black'
)
)
)
)
)
);
So i have my attributes 
but i can't to matching them with variations
You can use variations/batch and used your existing product attributes , its works for me...

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With