WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

Create new product with variations

Open cs090006 opened this issue 9 years ago • 1 comments

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

cs090006 avatar Jun 16 '16 08:06 cs090006

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

cs090006 avatar Jun 24 '16 10:06 cs090006