-1

I wanted to add a product with variations using the wordpress/woocommerce api.

I can successfully add a product with images and attributes but cannot convert these attributes to variations.

Here is the code, i used using JSON format in postman or any api client.

I am able to add the product with attributes saved associated with the product. However the variations don't register nor does the variation price.

{  "name": "Ship Your Idea",
  "type": "variable",
  "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.",
  "regular_price":"24",
  "categories": [
    {
      "id": 9
    },
    {
      "id": 14
    }
  ],
  "images": [
    {
      "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg"
    }
  ],
  "attributes": [
    {
      "id": 6,
      "position": 0,
      "visible": false,
      "variation": true,
      "options": [
        "Black",
        "Green"

      ]

    },
    {
      "name": "Size",
      "position": 0,
      "visible": true,
      "variation": true,
      "options": [
        "S",
        "M"
      ]
    }
  ],
  "default_attributes": [
    {
      "id": 6,
      "option": "Black"
    },
    {
      "name": "Size",
      "option": "S",
      "regular_price": "9.00"
    }
  ]
}
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50

1 Answers1

0

You cannot create variations while creating variable product with attributes. Woo commerce API does not support it.

  1. First create variable product with attributes and options.
  2. Then try to create variations using attribute and options.

Post: http://woo.example.com/wp-json/wc/v3/products/variabl_productid/variations

BODY:
{
    "regular_price": "9.00",
    "attributes": [
        {
            "name": "Color",
            "option": "black"
        }
    ]
}