skip to Main Content

I’m using WooCommerce API to update a specific product. I’m sending the following:

{
    "regular_price": "4000",
    "stock_quantity": 1
}

I’m getting a 200 OK with the PUT request, but the following response:

{
...
    "regular_price": "3000",
...
    "stock_quantity": 0,
...
}

Basically, no update is being performed.

How can I troubleshoot this specific problem? WordPress 5.5.3, WooCommerce 4.7.1, SiteGround as host.

2

Answers


  1. Solution of product updat issue:

    1. you can not update product price when product type is "variable" using WooCommerce API.
    2. you can’t see product price in website when you selected product type as "variable product" in admin panel.
    3. if you want to change product price then you have to change product type as "simple product".

    {"type": "simple","price": "90"}

    Solution of product stock issue

    1. if you want update stock then your have to make enable manage_stock parameter as true. then you can update stock quentity stock_quantity as 10.

    {"manage_stock": true,"stock_quantity": "1000" }

    Login or Signup to reply.
  2. I see that the behaviour depends totally of the tool you are using (e.g Curl, postman, node.js, etc)

    It is true that there are some specific conditions to be able to update stocks. Let’s work under the assumption that such conditions are set and the situation is exactly as indicated in the question: 200 OK answer, and output of product exactly as it was before.

    In my use case, I’d found exactly same situation in this post. I was under the same situation described in the thread where it was working with the curl example provided by Woocommerce support but not in postman:

    curl -X PUT https://domain_name/wp-json/wc/v3/products/<<product_id>>  
    -u <<customer_key>>:<<customer_secret>> 
    -H "Content-Type: application/json" 
    -d '{"stock_quantity": "70"}'
    

    After checking several option I’d noticed that curl generated by postman contains the auto-generated header:
    –header ‘Content-Type: text/plain’

    after disabling the auto-generated content-type in postman and adding application/json, the generated curl will have the header as:
    –header ‘Content-Type: application/json’

    It solved the issue both directly with postman and its generated curl command.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search