Marketplaces / WooCommerce Technical Sccope / WooCommerce Product Management / WooCommerce Update Stock

WooCommerce Update Stock

Version Date Created / Updated Notes
v1.0 05/28/2025 Hristiyan Georgiev Initial version

Just like price updates, when we are doing stock updates to WooCommerce, we have to consider two things - are we doing a product stock update or variant stock update. We have two separate calls for this and we will need to implement internal logic in order to know when to use the correct call.

All trigers, validations etc. are as per our abstraction - Stock Update general requirements

Product Stock Update

API Call : POST /wp-json/wc/v3/products/batch API Docs : https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#batch-update-products

We only want to use this call, when the product we are trying to update is NOT part of a variation i.e it is a single product. We could check this by the Listing > Listing Variation Group has to be empty.

Please note that we can include up to 100 objects to be updated.

Example call :

{
  "update": [
    {
      "id": 77,
      "stock_quantity": 21,
      "manage_stock": "true"

    }
  ]
}

Call mapping :

WooCommerce Field MCPro Field Notes
update Hardcoded as “update”
id Listing > Channel Item ID
stock_quantity Listing > Quantity
manage_stock Hardcoded as “true”

Example success response :

{
    "id": 74,
    "name": "Hoodie with stripes",
    "slug": "hoodie-with-stripes-2",
    "permalink": "https://sociable-sable-b1ae91.instawp.xyz/product/hoodie-with-stripes-2/",
    "date_created": "2025-05-21T13:37:50",
    "date_created_gmt": "2025-05-21T13:37:50",
    "date_modified": "2025-05-28T08:14:53",
    "date_modified_gmt": "2025-05-28T08:14:53",
    "type": "variable",
    "status": "publish",
    "featured": false,
    "catalog_visibility": "visible",
    "description": "WEweweqweqweqweqweqweqweqw",
    "short_description": "Test testov testovak",
    "sku": "321321",
    "price": "106",
    "regular_price": "",
    "sale_price": "",
    "date_on_sale_from": null,
    "date_on_sale_from_gmt": null,
    "date_on_sale_to": null,
    "date_on_sale_to_gmt": null,
    "on_sale": true,
    "purchasable": true,
    "total_sales": 0,
    "virtual": false,
    "downloadable": false,
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "external_url": "",
    "button_text": "",
    "tax_status": "taxable",
    "tax_class": "",
    "manage_stock": true,
    "stock_quantity": 25,
    "backorders": "no",
    "backorders_allowed": false,
    "backordered": false,
    "low_stock_amount": null,
    "sold_individually": false,
    "weight": "150",
    "dimensions": {
        "length": "10",
        "width": "20",
        "height": "30"
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": 0,
    "reviews_allowed": true,
    "average_rating": "0",
    "rating_count": 0,
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "purchase_note": "",
    "categories": [
        {
            "id": 21,
            "name": "Hoodies",
            "slug": "hoodies"
        }
    ],
    "tags": [
        {
            "id": 20,
            "name": "cool_product",
            "slug": "cool_product"
        },
        {
            "id": 22,
            "name": "mamka ti",
            "slug": "mamka-ti"
        }
    ],
    "images": [
        {
            "id": 80,
            "date_created": "2025-05-21T14:55:08",
            "date_created_gmt": "2025-05-21T14:55:08",
            "date_modified": "2025-05-21T14:55:08",
            "date_modified_gmt": "2025-05-21T14:55:08",
            "src": "https://sociable-sable-b1ae91.instawp.xyz/wp-content/uploads/2025/05/lion-2071739_1280.jpg",
            "name": "lion-2071739_1280",
            "alt": ""
        },
        {
            "id": 81,
            "date_created": "2025-05-21T14:56:28",
            "date_created_gmt": "2025-05-21T14:56:28",
            "date_modified": "2025-05-21T14:56:28",
            "date_modified_gmt": "2025-05-21T14:56:28",
            "src": "https://sociable-sable-b1ae91.instawp.xyz/wp-content/uploads/2025/05/nature-13298_1280.jpg",
            "name": "nature-13298_1280",
            "alt": ""
        }
    ],
    "attributes": [
        {
            "id": 1,
            "name": "Size",
            "slug": "pa_size",
            "position": 0,
            "visible": true,
            "variation": true,
            "options": [
                "L",
                "M",
                "S"
            ]
        }
    ],
    "default_attributes": [],
    "variations": [
        77,
        78,
        79
    ],
    "grouped_products": [],
    "menu_order": 0,
    "price_html": "<span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">&#36;</span>106.00</bdi></span> &ndash; <span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">&#36;</span>111.00</bdi></span>",
    "related_ids": [],
    "meta_data": [
        {
            "id": 146,
            "key": "_children",
            "value": []
        }
    ],
    "stock_status": "instock",
    "has_options": true,
    "post_password": "",
    "global_unique_id": "",
    "permalink_template": "https://sociable-sable-b1ae91.instawp.xyz/product/%pagename%/",
    "generated_slug": "hoodie-with-stripes-2",
    "brands": [],
    "_links": {
        "self": [
            {
                "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products/74",
                "targetHints": {
                    "allow": [
                        "GET",
                        "POST",
                        "PUT",
                        "PATCH",
                        "DELETE"
                    ]
                }
            }
        ],
        "collection": [
            {
                "href": "https://sociable-sable-b1ae91.instawp.xyz/wp-json/wc/v3/products"
            }
        ]
    }
}

Example error response :

{
    "code": "woocommerce_rest_invalid_product_id",
    "message": "To manipulate product variations you should use the /products/&lt;product_id&gt;/variations/&lt;id&gt; endpoint.",
    "data": {
        "status": 404
    }
}

We don’t need to map anything from the success response.If we have errors want to store the error from message and mark the product as per the abstraction Stock Update general requirements

Variant Stock Update

API Call : POST /wp-json/wc/v3/products/{productId}/variations/batch

API Docs : https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#batch-update-product-variations

The {productId} is our parent id. We pick it from Listing> Channel Item ID.

We only want to use this call if we are updating product(s) that is/are part of a variation.

Please note that we can include up to 100 objects to be updated.

The call body is the same as the product price update call. The only difference in mapping is that for id we want to pick Listing WooCommerce > Variant ID

The responses and response mappings are the same as the Product Stock Update call.

Is this article helpful?
0 0 0