0

after creating a product, and creating global attributes, I must add variations to the product, using API v3. this is the function:

function createVariationsById($id) {
    $woocommerce = getWoocommerceConfig();

    $data = [
        'regular_price' => '15.00',
        'manage_stock' => true,
        'stock_quantity' => 10,
        'attributes' => [
            [
                'id' => 8,
                'name' => 'Taglia',
                'option' => 'S'
            ],
        ],
    ];

    echo json_encode($woocommerce->post('products/' . $id . '/variations', $data));
}

only the attributes are not added.

but the attribute with id 8 has already been created globally.

EDIT I did and posted the example here: https://github.com/mattepuffo/Woocommerce-api-import

matteo
  • 2,121
  • 4
  • 20
  • 33
  • duplicated please check the answar here:https://stackoverflow.com/questions/47518280/create-programmatically-a-woocommerce-product-variation-with-new-attribute-value – Saharis9988 Apr 18 '20 at 21:48
  • sorry but in that post I didn't find the answer, as they don't use APIs! – matteo Apr 19 '20 at 07:46

0 Answers0