Create new product with variations
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 codered.
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.
I have "Any color" instead "red"
Could you please help me?
'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' ) ) ) )
i found same issue wihtout answers
I found a solution
'variations' => array( array( 'sku' => date('His').'_1', 'regular_price' => '29.98', 'attributes' => array( array( 'id' => date('YmdHis', strtotime('+2 seconds')), 'slug'=>'color', 'name'=>'color', 'option'=>'red' ) ) ), array( 'sku' => date('His').'_2', 'regular_price' => '29.98', 'attributes' => array( array( 'id' => date('YmdHis'), 'slug'=>'color', 'name'=>'color', 'option'=>'black' ) ) ) )
works for me if color attribute and red,black values exist