tr Skip to content

When a new order is created in WooCommerce, loop through the line items using Iterator, call WooCommerce PHP function wc_get_product to get the product data for the product ID, and add details to Google Spreadsheet

Each new WooCommerce order is split into its line items with an Iterator. For every item, a PHP Functions step calls wc_get_product on the product ID, and the result goes into a new Google Sheets row.

WooCommerce Iterator PHP Functions by FlowMattic Google Sheets

4 steps Setup ~8 min Used on 3.1k sites Free to import

The When a new order is created in WooCommerce, loop through the line items using Iterator, call WooCommerce PHP function wc_get_product to get the product data for the product ID, and add details to Google Spreadsheet workflow on the FlowMattic canvas, with 4 steps across WooCommerce, Iterator, PHP Functions by FlowMattic, Google Sheets
The workflow as it appears in the builder after import. Each step opens for editing.

What this workflow does

An order record tells you what was bought, but a line item on its own carries little about the product behind it. If you want a sheet where every sold item sits on its own row next to product details from your catalog, you need to look each product up. This template does that lookup inside WordPress, item by item.

The WooCommerce trigger fires as soon as an order is placed in your shop, and its data starts the run. An Iterator then loops through the order's line items, so the next two steps repeat once per item. In each pass, the PHP Functions step calls WooCommerce's wc_get_product function with that item's product ID, which reads the product from your own store database.

The last step writes a row to Google Sheets for the current item. You decide which columns hold order data, line item data and the product data the function returned. An order with three products gives you three rows. The Iterator and the PHP step ship without settings, so you point the Iterator at the line items array and set the function and its parameter after import. A test order shows exactly what each step returns.

Item-level sales sheet with SKUs

A store owner wants one row per product sold, with the SKU and current price read from the catalog, to sort and total in Google Sheets without exporting orders.

Supplier reorder log

A shop that buys stock from several suppliers logs each sold item with product data from wc_get_product, then filters the sheet by product to see what to reorder.

Commission tracking per product

A marketplace-style store pays makers per item. Each line item becomes a row the bookkeeper can match to the maker who supplied that product.

How this workflow runs

What happens at each step once the workflow is on, and what you need before you import it.

  1. Step 1Trigger
    WooCommerce New Order Created

    Starts the workflow whenever WooCommerce creates an order. The order data, including its list of line items, is passed on for the Iterator and the later steps to use.

  2. Step 2Logic
    Iterator Loop Through Array

    Loops through the array you map here, which should be the order's line items. The steps after it run once for each item, using that item's data such as its product ID.

  3. Step 3Action
    PHP Functions by FlowMattic Call PHP Function

    Calls a PHP function on your site for the current item. Set it to wc_get_product and pass the line item's product ID. Run a test order to see which product values come back for mapping.

  4. Step 4Action
    Google Sheets Add New Row

    Adds a row to your chosen Google Sheets spreadsheet for the current line item. Map columns to order fields, item fields and the values the PHP step returned, and connect your Google account.

What you need

  • FlowMatticCore
  • WooCommerce PluginPlugin
  • Google Sheets AccountAccount

After importing, map your own data. To keep the template universal, not every step is pre-filled. Open each step in the builder and connect your accounts and fields (channels, lists, sheets, recipients) before you switch the workflow on.

Make it yours

Changes worth making after you import it.

  • Place a test order with two different products after import. You can then pick the line items array in the Iterator and see the PHP step's output for each item before you map the sheet columns.
  • Add a Filter after the Iterator that continues only for items in one product category or with a set SKU prefix. Items that fail it are skipped, and the loop moves on to the next item.
  • Put the order number in the first column of the sheet. Rows from the same order then group together when you sort, even if a large order spans many rows.

Questions about this workflow

Does every WooCommerce line item get its own Google Sheets row?

Yes. The Iterator runs the PHP step and the Google Sheets step once for each item in the array you map, so an order with four line items adds four rows.

Why call wc_get_product instead of using the order data?

The order lists what was bought, while wc_get_product reads the product itself from your store. That lets you log product details the line item may not include. Check a test run to see which values your setup returns.

Does the PHP Functions step send my product data anywhere?

No. The function runs on your WordPress site, where WooCommerce and FlowMattic are installed. Only the Google Sheets step sends data out, to the spreadsheet you choose.

Will orders placed before import be added to the sheet?

No. The trigger fires on orders created after you turn the workflow on. Past orders stay in WooCommerce and are not copied.

Import this workflow into your WordPress site

Download the JSON, import it from the Workflows screen and connect your accounts. Every run stays on your server, with no per-task fees.

30-day money-back guarantee Unlimited workflows and runs Self-hosted

Customers who run it every day

Rated 4.8 out of 5 by customers
Read more reviews

No additional usage fees over and above the annual fee ... AND Technical Support is great... they get back to you quite quickly and go above and beyond what is expected...

Verified User in Consumer Goods

Crafting bridges between my favorite apps, FlowMattic has truly impressed me with its ability to seamlessly automate workflows. This has noticeably accelerated the efficiency of my business processes, making everything run more smoothly and productively.