Table Of Contents
- Introduction
- Step 1: Create an outgoing configuration
- Step 2: Create a route
- Step 3: (Optional) Get the customer ID from WooCommerce by email address or username
- Additional information
Introduction
This article describes how to update customers 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 customers.
- Insert a name in the “name” field.
- For example: “WooCommerce – Customers – Update a customer”
- Under “Publisher” select “WooCommerce - Customer - Update a customer”
- Under “WordPress user id”, specify the path where the customer’s user ID is stored within the data, using the “&{}” notation.
- You should change the section between the brackets to any identifier used within your system to recognize which WordPress user/customer we should update. For this purpose, it’s most common to store the WooCommerce Customer ID, either in the data in your system or in a storage within Alumio.
- For example: “&{customer_id}” or “&{customer.id}”.
- When you don’t know the customer ID at this point, see step 3 for a way to find the customer ID based on email address or username.
- Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
- Click “Add entity transformer” and select “WooCommerce - Customer - Restructure from Alumio customer”.
- This transformer converts data from the Alumio customer 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 customer ID from WooCommerce by email address or username
When you don’t already know the customer ID, you can look it up by searching for a user’s email address or username in the WordPress website using the following steps.
- In the route, click “Add entity transformer” and select the “Data, transform data using mappers and conditions” transformer.
- Click “Add data transformer” within the newly created transformer and select the “Merger transformer” option.
- When you want to check if a customer exists based on email address:
- Under “Data transformer”, select “WooCommerce - Customer - Get Customer By Email”.
- Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
- Under “Email”, specify the path where the customer’s email address is stored within the data, using the “&{}” notation.
- For example: “&{email}” or “&{customer.email}”.
- When you want to check if a customer exists based on username:
- “Under “Data transformer”, select “WooCommerce - Customer - Get Customer By Username”.
- Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
- Under “Username”, specify the path where the customer’s username is stored within the data, using the “{}” notation.
- For example: “&{username}” or “&{customer.username}”.
- Under “Template”, fill in the following template:
{
"WooCommerceUser": "&{@}"
}
- 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 “WooCommerceUser”.
- This value should match the first key specified in the “Template” in the previous steps.
- Select “Add conditions” and select “Is not empty”.
- Save the route and go back to the outgoing configuration that you created in the previous step.
- Set the “WordPress user id” field to “&{WooCommerceUser[0].id}”
Additional information
If you added the check in step 3, no task will be created in your Alumio dashboard if the user does not already exist in the WooCommerce website.
If you wish to always update the same customer, you can just set that WordPress user ID in the “WordPress user id” field in the outgoing configuration. This is especially useful when testing the integration. In this situation, you can leave out “&{}” notation. For example: “12”.
This outgoing configuration uses the Alumio customer schema.
That’s it!
You should now be able to update customers in WooCommerce!