Update stock at sku level via woocommerce API using the update_stock function

0

I can update the inventory at the product size ID level, but I can not get the sku level.

client code that calls the API.

$id = '13216';
        $quantity = '1';
        $result = $client->products->update_stock( $id, $quantity);
        print_r($result);

This is the function in the 'class-wc-api-client-resource-products' file

/**
     * Update the stock quantity for a product
     *
     * PUT /products/#{id} with stock quantity
     *
     * @param int $id order ID
     * @param int|float $quantity new stock quantity
     * @return array|object newly-updated product
     */
    public function update_stock( $id, $quantity ) {

        $this->set_request_args( array(
            'method' => 'PUT',
            'path'   => $id,
            'body'   => array( 'stock_quantity' => $quantity ),
        ) );

        return $this->do_request();
    }

The array generated by the response looks like this:

[product] => stdClass Object
        (
            [title] => CALÇA JEANS FLARE DE VELUDO - 23
            [id] => 13216
            [created_at] => 2018-01-31T15:43:26Z
            [updated_at] => 2018-01-31T15:43:26Z
            [type] => variation
            [status] => publish
            [downloadable] => 
            [virtual] => 
            [permalink] => https://fashionwe.com.br/loja/calca-jeans-flare-de-veludo/?attribute_pa_tamanho=23
            [sku] => 163835523349
            [price] => 1280.00
            [regular_price] => 1280.00
            [sale_price] => 
            [price_html] => R$ 1.280,00
            [taxable] => 
            [tax_status] => taxable
            [tax_class] => 
            [managing_stock] => 1
            [stock_quantity] => 1
            [in_stock] => 1
            [backorders_allowed] => 
            [backordered] => 
            [sold_individually] => 
            [purchaseable] => 1
            [featured] => 
            [visible] => 1
            [catalog_visibility] => visible
            [on_sale] => 
            [product_url] => 
            [button_text] => 
            [weight] => 
            [dimensions] => stdClass Object
    
asked by anonymous 07.02.2018 / 15:20

0 answers