Skip to content

WooCommerce Lookups

The WooCommerce connector answers IMan's CustomLookup function. It reads a resource from the store's REST API and returns one value from WooCommerce's answer. Call it from any expression to translate a SKU or an email address into a WooCommerce id, or to check that a record exists.

CustomLookup

Syntax

CustomLookup( systemid, select, from, where, "", mustreturnvalue )

Arguments

  • systemid
  • select
    • The JPath of the value to return.
    • A resource such as products answers with a list. Start the path with [] to read from the first record in the list, such as []/id.
    • A single record, such as products/123, answers with the record itself. Give the field's name alone, such as name.
  • from
    • The resource to read, under /wp-json/wc/v3/, such as products, customers, orders or products/categories.
  • where
    • The query string WooCommerce filters by, without the ?, such as "sku=" & %Item. Join two filters with &. The WooCommerce REST API documentation lists each resource's filters.
  • The fifth argument
    • Not used. Pass "".
  • mustreturnvalue
    • True or False.
    • True: the function raises an error when the lookup returns no value.
    • False: the function returns an empty value when the lookup returns no value.

Remarks

  • Each distinct query runs once. IMan keeps WooCommerce's answer for each System Connector and query, including an answer with nothing in it. A thousand records that look up the same SKU send one request. A lookup does not see a change made in WooCommerce after its first answer.
  • The lookup reads the first page. WooCommerce answers a list ten records at a time. Make the filter match one record. With several matches, the lookup returns the first.
  • Encode + and & in a value. IMan decodes the query string before sending it. A + in a value reaches WooCommerce as a space, and an & starts a new filter. Write them as %2B and %26, such as Replace(%Email, "+", "%2B") for an email address like [email protected]. A space needs no change.
  • An unknown resource raises an error: "Error performing WooCommerce lookup. The resource [...] is not valid."

The REST API key needs Read permissions, or Read/Write.

Examples

A product's id from its SKU

Returns the id of the product with the SKU in %Item, or an empty value when the store has none:

CustomLookup("WOOCOMMERCE", "[]/id", "products", "sku=" & %Item, "", False)

Map the result to Id on a Products push with Insert/Update. The push updates the product when the lookup finds it and creates it when the lookup comes back empty.

A variation's ids from its SKU

Filtering products by SKU finds variations too. For a variation, id is the variation's own id and parent_id is its product's:

CustomLookup("WOOCOMMERCE", "[]/id", "products", "sku=" & %Item, "", True)
CustomLookup("WOOCOMMERCE", "[]/parent_id", "products", "sku=" & %Item, "", True)

Map the first to Variation Id and the second to Product Id on a Variations push. The second call reads the answer IMan kept from the first and sends nothing.

A customer's id from an email address

Returns the id of the customer with the email address in %Email:

CustomLookup("WOOCOMMERCE", "[]/id", "customers", "role=all&email=" & Replace(%Email, "+", "%2B"), "", False)

Without role=all, WooCommerce searches only the users with the Customer role.

A category's id from its slug

Returns the id of the product category with the slug in %Category, for Default Category on a Products push:

CustomLookup("WOOCOMMERCE", "[]/id", "products/categories", "slug=" & %Category, "", True)