[Guide] Updating stock in WooCommerce

Introduction

This article describes how to update products in WooCommerce.

Step 1: Create an outgoing configuration

  • Navigate to “Connections” in the menu and select “Outgoing”.
  • Create a new outgoing configuration to setup the process of updating WooCommerce stock values.
  • Insert a name in the “name” field.
    1. For example: “WooCommerce – Products – Update stock”.
  • Under “Publisher” select “WooCommerce - Product - Update stock”.
  • Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
  • Under “Product Id”, specify the path where the product ID is stored within the data, using the “&{}” notation.
    1. For example: “&{identifier}” or “&{product.id}”.
    2. When you don’t know the product ID at this point, see step 3 for a way to find the product ID based on SKU.
  • Click “Add entity transformer” and select “WooCommerce - Product Update Stock - Restructure from Alumio”.
    1. This transformer converts data from the InventoryLevel property from the Alumio offer schema to a format that WooCommerce understands.

Step 2: Create a route

Next you’ll create a route to bind the incoming configuration to the outgoing configuration. In the route, you’ll need to select the outgoing configuration you created in the previous steps.

On the following links, you can find more information about creating routes and incoming configurations and subscribers.

Step 3: (Optional) Get the product ID from WooCommerce by looking up a SKU

When you don’t already know the product ID or whether the product already exists, you can look it up by searching for a SKU in the WordPress website using the following steps.

  • In the route, click “Add entity transformer” and select the “WooCommerce - Product - Find Product by SKU” transformer.
  • Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
  • Under “Sku”, specify the path where the product’s SKU is stored within the data, using the “&{}” notation.
    1. For example: “&{sku}” or “&{product.sku}”.

  • Click “Add entity transformer” at the bottom of the page and select the “Data, transform data using mappers and conditions” transformer.
  • Click “Add filter” and select “Value condition”.
  • Under “Accessor” select “Pattern accessor”.
  • Under “Pattern” insert “WooCommerceProduct”.
  • Select “Add conditions” and select “Is not empty”.

  • Click “Add data transformer” and select “List mapper”
  • Under “Accessor”, select “Key accessor”
  • Click “Add mapper” and select “List: Extend with supplied data”
  • Under “Array”, fill in the following template:
    {

“identifier”: “&{WooCommerceProduct[0].id}”

}

  • Save the route and go back to the outgoing configuration that you created in the previous step.
  • Set the “Product Id” field to “&{identifier}” in case you set it to a different value before.
    1. This value should match the first key specified in the “Array” in the previous steps.

Additional information

If you added the check in step 3, no task will be created in your Alumio dashboard if the SKU does not already exist in the WooCommerce website.

There’s also a transformer available (“WooCommerce - Product Update Stock - Restructure from Alumio with sending data”) that has the same functionalities as this outgoing configuration. You can use this in case you like to add additional steps in your route after you update the stock.

It’s currently not possible to update an individual variant.

This outgoing configuration uses the InventoryLevel property from the Alumio offer schema.

That’s it!

You should now be able to update stock values in WooCommerce!