I’m currently creating a WordPress / WooCommerce plugin that adds products via REST API. This products have two variations regarding their license. I’ve checked the documentation and so far I’m able to create the product with the attributes. However, when it comes to create the variaton for those attributes I can’t seem to find the right syntaxis.

This is my array containing the data:

$data = [
    'name' => 'Test picture 7',
    'type' => 'variable',
    'description' => 'Test product',
    'categories' => [
            'id' => 9
    'images' => [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
            'position' => 0
    'attributes' => [
            'name' => 'License',
            'position' => 0,
            'visible' => true,
            'variation' => true,
            'options' => [

print_r($woocommerce->post('products', $data));

So far I’ve checked and so far no answer has been able to create both things at the same time. I’ve also thought of creating the variations after the product has been created but since the ID of the product is read only I can’t seem to figure how to retrieve that specific product to add the variations.

Read more here: Add Woocommerce both Attributes and Variations in the same REST API post


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: