[Guide] Creating or updating customers in WooCommerce

Table Of Contents

  • Introduction
  • Step 1: Create an outgoing configuration
  • Step 2: Create a route
  • Step 3: Get the customer ID from WooCommerce by email address or username
  • Additional information

Introduction

This article describes how to create or update customers in WooCommerce in one integration.

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 creating and updating WooCommerce customers.
  • Insert a name in the “name” field.
  1. For example: “WooCommerce – Customers – Upsert a customer”
  • Under “Publisher” select “WooCommerce - Customer - Create or update a customer”
  • 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”.
  1. 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: Get the customer ID from WooCommerce by email address or username

At this step, you need to check if the user’s email address or username already exists in the WordPress website, to either use the existing customer ID or create a new customer.

  • 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:1. Under “Data transformer”, select “WooCommerce - Customer - Get Customer By Email”.2. Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.3. 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:
    1. “Under “Data transformer”, select “WooCommerce - Customer - Get Customer By Username”.
    2. Under “WooCommerce HTTP client” select the HTTP client that you created during the initial setup.
    3. 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": "&{@}"
}

HTML

  • Click “Add data transformer” at the bottom of the page and select the “Conditional transformer” transformer.
  • Click “Add data transformer” and select the “List mapper” transformer.
  • Under “Accessor” select “Pattern accessor”.
  • Click “Add mapper” and select the “List: Extend with supplied data” mapper.

Under “Array”, fill in the following template:

{
  "identifier": "&{WooCommerceUser[0].id}"
}

  • Click “Add filter” and select “Value condition”.
  • Under “Accessor” select “Pattern accessor”.
  • Under “Pattern” insert “WooCommerceUser”.
  • Select “Add conditions” and select “Is not empty”.

  • Save the route.

Additional information

This outgoing configuration uses the Alumio customer schema.

That’s it!

You should now be able to create and update customers in WooCommerce in one route!