Updating stock via Woocommerce API V2

RayZor

I'm trying to update my woocommerce shop's stock levels via the API interface. I'm using the kloon/WooCommerce-REST-API-Client-Library but unfortunately it only seems to read product information and doesn't allow me to PUT stock info.

Reading the API docs I can see I can update a product using the following:

curl -X PUT https://example.com/wc-api/v2/products/546 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "product": {
    "regular_price": "24.54"
  }
}'

But non of the function in the API client library access the PUT features of product, I have found a modified client library for the V2 api rodolfojnn/WooCommerce-REST-API-Client-Library which has updated PUT functions:

/**
* Update a product by id
* @param int $product_id
* @param array $data
* @param string $method
* @return mixed|json string
*/
    public function update_product($product_id, $data, $method = "PUT") {

        return $this->_make_api_call('products/' . $product_id, ['product' => $data], $method);
}

But this now throws an Parse error: syntax error, unexpected '[' error because of the ['product' => $data] bit - I tried converting it to an array but that also errors, anyone any idea why (I'm running this in codeigniter btw)

aniket

try modifying

public function update_product($product_id, $data, $method = "PUT") {

    return $this->_make_api_call('products/' . $product_id, $data, $method);
}

Pass only $data as 2nd parameter to update_product

$data=  json_encode(

    array( 'product' =>

       array( 
          'regular_price'        => "10.26",
          'managing_stock'   => true,
          'in_stock'         => true,
          'stock_quantity'   => 45
       )
    )
);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Training Dialogflow agent via API V2

分類Dev

Updating ACF via REST API v3

分類Dev

Mailchimp API v2

分類Dev

Dialogflow v2 NodeJS API ContextsClient

分類Dev

Google Maps Android API v2

分類Dev

Bing Ads API v2 oAuth2

分類Dev

How get variation's stock quantity woocommerce

分類Dev

Which hooks for WooCommerce stock saved or updated

分類Dev

Google Maps Android API v2 Authorization failure

分類Dev

Office api V2 authentication multiple resources in scopes

分類Dev

How to run playbook api in Ansible v2 with vault

分類Dev

dialogflow v2 apiのapp.setContext()?

分類Dev

paypal v2 curl api invalid_client

分類Dev

Can't connect to Google Maps Api Android V2

分類Dev

polyline width conversion map api v2

分類Dev

android maps api v2 adding multiple circles

分類Dev

Overlay an image on google maps android api v2

分類Dev

最小API10のGoogleMap v2

分類Dev

Fluent-Nhibernate + Web Api v2 + Unity

分類Dev

How to set api key for Google maps v2

分類Dev

Google map API v2 Android - Markers & scale

分類Dev

How to download and use offline maps in Map API V2?

分類Dev

How to change Language on Android google map V2 api

分類Dev

Google Maps V2 - API key not found Error Message

分類Dev

Updating a 'this' value in a service via a function

分類Dev

Updating programmatically customer's billing information in WooCommerce

分類Dev

Orion CB: Can't Access Entities via /v2/entities endpoint

分類Dev

Display an estimated delivery date range based on WooCommerce cart item stock

分類Dev

Avoid stock reduction on COD orders with proscessing status in Woocommerce

Related 関連記事

ホットタグ

アーカイブ