BUT. Honestly

Clarity without the comfort

Honest writing by Nicola Mustone on the messy overlap between humans and tech.

WooCommerce CLI Product Management: A Practical Guide

WooCommerce CLI Product Management: A Practical Guide

Time to Read

8–11 minutes
15 comments on WooCommerce CLI Product Management: A Practical Guide

Everything you can do in the WooCommerce product editor, you can handle with WooCommerce CLI product management directly in your terminal.

Quick Summary
  • WooCommerce CLI product management lets you handle products from the terminal with repeatable, scriptable commands.
  • You can create simple, external, grouped, and variable products, including attributes and variations defined as arrays.
  • Deleting, updating, and bulk operations become single commands instead of long sessions in the product editor.
  • For heavy catalogs or frequent changes, the CLI turns product management into a reliable workflow instead of manual busywork.
Table of Contents

Clicking through the product editor is fine when you have ten products. It turns into a slog when you have hundreds. Or when you need to make the same change across the entire catalog.

WooCommerce CLI, built on top of WP-CLI, lets you manage products without leaving the terminal. No loading spinners. No mouse. Just clear, repeatable commands you can script and automate.

This guide walks through the basics of creating, updating, and deleting products with WooCommerce CLI, including variable products and bulk operations.

What You Can Do With WooCommerce CLI

With WooCommerce CLI, you can:

  • Create products
  • Import products from a file
  • Update existing products
  • Delete products
  • Get a single product
  • List all products
  • Get registered product types
  • Get product categories

For the full list of commands and options, refer to the official WooCommerce CLI documentation, which is updated as WooCommerce evolves.

Here I will focus on practical examples that are either missing from the docs or easy to get wrong in practice, like variable products and bulk operations.

In the examples below, I split the command on multiple lines by using the that you see at the end of each line. This makes it simpler to read on the site. You can skip that and write the command on a single line, if you prefer to do so.

Creating WooCommerce Products from the Terminal

You can create every default WooCommerce product type that exists in the editor:

  • Simple
  • External
  • Grouped
  • Variable

You can do it one product at a time, or drive everything from a CSV or text file when you want to scale it up.

Simple Products

Creating a simple product is a good baseline. This command creates a simple product with the title “Test Product,” SKU WCCLITESTP, and a regular price of 20:

wp wc product create 
  --title="Test Product" 
  --type=simple 
  --sku=WCCLITESTP 
  --regular_price=20

Run it and you will see the new product appear in your WooCommerce dashboard, just as if you had created it through the editor.

External Products

External products work the same way as simple products, but they point to a URL instead of a local add to cart action.

On top of the simple product fields, you can set a product URL and the button text:

wp wc product create 
  --title="External Product Test" 
  --type=external 
  --sku=WCCLIEXTERNAL 
  --regular_price=20 
  --product_url="https://domain.com/product/test/" 
  --button_text="Buy me"

The URL and button text are technically optional, but in practice you should set at least the --product_url. If you forget it here, you will have to edit the product by hand later, which defeats the purpose of using the CLI.

Grouped Products

A grouped product is a container for other simple products. You create the grouped product first, then assign child products to it.

Create the grouped product:

wp wc product create 
  --title="Grouped Product" 
  --type=grouped 
  --sku=WCCLITESTGROUPED

The command will print the new product ID. You will need that ID when you attach simple products.

When you create a simple product that belongs to this group, pass the grouped product ID as the parent:

wp wc product create 
  --title="Grouped Child Product" 
  --type=simple 
  --sku=WCCLIGROUPEDCHILD 
  --regular_price=15 
  --parent_id=123

Replace 123 with the ID of your grouped product. Any simple product created with that --parent_id will appear inside the group in WooCommerce.

Variable Products

Variable products are where WooCommerce CLI gets interesting. Handling attributes and variations from the terminal is where many store owners first feel the payoff of WooCommerce variable products CLI workflows.

Variable products combine attributes (like Color or Size) with multiple variations, each with its own price and settings. Understanding the difference between attributes and variations can take a moment, so I wrote a detailed essay about it.

WooCommerce CLI treats attributes and variations as arrays. You refer to each one by its index in that array. Indexes start at 0, not 1.

For example, to set the regular price for the first variation, you use:

--variations.0.regular_price=20

The same pattern applies to attributes:

--attributes.0.name="Color"

Let us create a simple variable product with two attributes, Color and Size, and a set of variations that combine them.

wp wc product create 
  --title="Variable Product Test" 
  --type=variable 
  
  --attributes.0.name="Color" 
  --attributes.0.visible=yes 
  --attributes.0.variation=yes 
  --attributes.0.options="Black|Blue" 
  
  --attributes.1.name="Size" 
  --attributes.1.visible=yes 
  --attributes.1.variation=yes 
  --attributes.1.options="Small|Medium" 
  
  --variations.0.attributes.color="Black" 
  --variations.0.attributes.size="Small" 
  --variations.0.regular_price=20 
  
  --variations.1.attributes.color="Black" 
  --variations.1.attributes.size="Medium" 
  --variations.1.regular_price=20 
  
  --variations.2.attributes.color="Blue" 
  --variations.2.attributes.size="Small" 
  --variations.2.regular_price=20 
  
  --variations.3.attributes.color="Blue" 
  --variations.3.attributes.size="Medium" 
  --variations.3.regular_price=20

Let us unpack what this does.

The first part creates the variable product itself:

wp wc product create 
  --title="Variable Product Test" 
  --type=variable

The next block defines the attributes:

--attributes.0.name="Color" 
--attributes.0.visible=yes 
--attributes.0.variation=yes 
--attributes.0.options="Black|Blue" 

--attributes.1.name="Size" 
--attributes.1.visible=yes 
--attributes.1.variation=yes 
--attributes.1.options="Small|Medium"

Here:

  • attributes.0 is the first attribute, Color, with options Black and Blue.
  • attributes.1 is the second attribute, Size, with options Small and Medium.
  • visible=yes makes the attribute visible on the product page.
  • variation=yes tells WooCommerce to use that attribute for variations.

The final block creates the variations:

--variations.0.attributes.color="Black" 
--variations.0.attributes.size="Small" 
--variations.0.regular_price=20 

--variations.1.attributes.color="Black" 
--variations.1.attributes.size="Medium" 
--variations.1.regular_price=20 

--variations.2.attributes.color="Blue" 
--variations.2.attributes.size="Small" 
--variations.2.regular_price=20 

--variations.3.attributes.color="Blue" 
--variations.3.attributes.size="Medium" 
--variations.3.regular_price=20

Each variations.N entry describes one specific combination of attributes and its price.

Two important rules to remember:

  • Indexes start at 0. Your first attribute or variation is 0, not 1.
  • Keep attribute names consistent. If you use color in one place and Color in another, things will break in surprising ways.

If you need more combinations, you keep adding more variations.N blocks.

Deleting WooCommerce Products

Deleting a single product by ID is straightforward:

wp wc product delete 123

Replace 123 with the product ID.

If you want to delete all products in bulk, you can pipe the output of a list command into delete. This is destructive, so use it only when you are sure you want a clean slate.

wp wc product delete $(wp wc product list --format=ids)

wp wc product list --format=ids returns only product IDs, one after another. The outer command then deletes each of those IDs.

Updating WooCommerce Products

Updating a product looks very similar to creating one. Instead of product create, you use product update and pass the product ID.

wp wc product update 123 
  --regular_price=25 
  --sale_price=20

This updates product 123 with a new regular price and sale price. You can pass any other fields you would normally use for creation.

Variations behave the same way. Each variation has its own ID and can be updated like a product:

wp wc product update 456 
  --regular_price=18

Here 456 is the variation ID. Treat variations as first class products when you update them.

Bulk Importing WooCommerce Products with CLI

Creating products one by one quickly becomes tedious. The real power of WooCommerce CLI product management shows up when you combine it with files and scripts for bulk imports.

One practical approach is:

  1. Keep your products in a CSV or text file.
  2. Use a script or a tool like Alfred to loop through that file.
  3. For each line, call wp wc product create with the right flags.

Remi Corson, a former colleague of mine at Automattic, has a detailed walkthrough of this pattern in his article on bulk importing WooCommerce products with WP-CLI and Alfred. It is a good reference if you are comfortable with scripts and want to turn product management into a repeatable workflow instead of a manual chore.

Example: Bulk Import Simple Products With Python And CSV

Here is a minimal, end to end example of importing simple products from a CSV file using Python and WooCommerce CLI.

First, define a CSV file named products.csv. You can create one using Microsoft Excel or Google Sheets. Below is a basic example:

title,sku,regular_price,type
T Shirt Black Small,TSHIRT-BLACK-S,19.90,simple
T Shirt Black Medium,TSHIRT-BLACK-M,19.90,simple
Mug White,MUG-WHITE,9.90,simple

Each row describes one product:

  • title is the product title.
  • sku is the SKU.
  • regular_price is the price as a number or string.
  • type is the WooCommerce product type, here always simple.

Next, create a Python script named import_products.py in the same directory:

import csv
import subprocess
from pathlib import Path

csv_path = Path("products.csv")

with csv_path.open(newline="", encoding="utf-8") as f:
    reader = csv.DictReader(f)

    for row in reader:
        title = row["title"]
        sku = row["sku"]
        regular_price = row["regular_price"]
        ptype = row.get("type", "simple")

        cmd = [
            "wp", "wc", "product", "create",
            f'--title={title}',
            f'--type={ptype}',
            f'--sku={sku}',
            f'--regular_price={regular_price}',
        ]

        print("Creating product:", title)
        subprocess.run(cmd, check=True)

What this script does:

  • Reads products.csv line by line.
  • Builds a wp wc product create command for each row.
  • Calls the command with subprocess.run, so each product is created through WooCommerce CLI.

To run the import, go to your WordPress project directory (where wp is available) and run:

python3 import_products.py

As long as the wp wc commands work when you type them by hand, they will work from Python too. The script just automates the typing.

You can extend this pattern:

  • Add more CSV columns for things like sale_price, description, or categories.
  • Branch on type to handle external or variable products differently.
  • Wrap the call in try/except to log errors without stopping the entire import.

The key idea is simple. The CSV is your source of truth, Python is the glue, and WooCommerce CLI is the interface to your store.

Why Use WooCommerce CLI At All

Working through the terminal is not for everyone. The product editor is still fine for small sites or rare changes.

The CLI starts to pay off when:

  • You manage many products.
  • You repeat the same changes often.
  • You want a clear history of what changed and when.
  • You want something you can automate or put in version control.

A single command can create an entire variable product with all its variations. Another command can clear a test catalog or update prices across a category. Once you trust the pattern, you save time every time you run it.

The main trade-off is learning the syntax and being careful with destructive commands. Scripts do not ask for confirmation unless you tell them to. A mistake in a bulk delete hurts more than a wrong click in the editor.

If you are willing to invest a bit of practice, WooCommerce CLI gives you a fast, scriptable layer over your store.

Share This Essay

Read the Comments

Leave a Reply to xavairelandCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Fred Avatar
    Fred

    Hi there,

    This is an awsome tutorial!

    Thank you for sharing your knowledge 🙂

    Fred

    1. Nicola Mustone Avatar
      Nicola Mustone

      You’re welcome!

  2. Fred Avatar
    Fred

    Hi,

    I looked at the article by Remi Corson and I don’t have a mac..
    Is there an alternative for windows user?
    Also Is it possible to import/export woo product using WooCommerce CLI?

    Thank you

    1. Nicola Mustone Avatar
      Nicola Mustone

      Hi Fred,

      Is there an alternative for windows user?

      I don’t have an alternative for Win, sorry.

      Also Is it possible to import/export woo product using WooCommerce CLI?

      It is, that script by Remi is a first step. The script to import/export products is harder than that though to write.

      I tried to write one but I don’t have a good knowledge of shell language so I wasn’t able to get it working properly.

      1. Andrew Avatar
        Andrew

        Nicely blog. I don’t know if they existed when you wrote this blog, but import & export now exist. Check wp help import and wp help export for details. Excerpts follow.

        wp import … –authors= [–skip=]

        Provides a command line interface to the WordPress Importer plugin, for performing data migrations.

        wp export [–dir=] [–skip_comments] [–max_file_size=]
        [–start_date=] [–end_date=] [–post_type=]
        [–post_type__not_in=] [–post__in=] [–start_id=]
        [–author=] [–category=] [–post_status=]
        [–filename_format=]

        Generates one or more WXR files containing authors, terms, posts,
        comments, and attachments. WXR files do not include site configuration
        (options) or the attachment files themselves.

  3. Fred Avatar
    Fred

    Hi Nicola,

    Thank you for your replies..
    One more question please.
    Is it possible to bulk delete all the product that are in the bin?
    I cannot find a status like ‘published’, ‘bin’ or ‘draft’
    Fred

    1. Nicola Mustone Avatar
      Nicola Mustone

      Hi Fred,
      You can use this command:

      wp wc product delete $(wp wc product list --post_status=trash --format=ids)
      
  4. Rob Benz Avatar
    Rob Benz

    Is there any way to add custom product meta to the list of available fields?

    I have added some custom product meta, and I would like the ability to update or create that field.

    ex

    wp wc product update 1234 –condition=”Like New” –SKU=12345

    where condition is a custom post meta added with woo_add_custom_general_fields()

    1. ilya Avatar
      ilya

      you can do it with
      “`
      wp post meta set POSTID METAKEY METAVALUUE
      “`

  5. steve Avatar
    steve

    This is great thanks for writing this. I was completely unaware wp-cli worked with woo.

    1. Nicola Mustone Avatar
      Nicola Mustone

      You’re welcome Steve! Glad you like it.

  6. Andrew Avatar
    Andrew

    I’m trying to automate installation of multiple sites. I’ve got everything working except I’m stuck on how to automate the setup wizard so that shop, cart, etc. pages get created, and whatever other details the setup wizard normally take care of. Any help?

    Thanks!

  7. Ryan Avatar
    Ryan

    This is a great article, but I wonder if it’s out of date?

    Woocommerce seems to be saying the CLI is deprecated and people should be using the REST API instead? I’m having a hard time figuring out the exact syntax of the “–attributes” option, but I’m coming up short.

    When I try your “array” method I get:

    Error: Parameter errors:
    unknown –title parameter
    unknown –attributes.0.name parameter
    unknown –attributes.0.visible parameter
    unknown –attributes.0.variation parameter
    unknown –attributes.0.options parameter
    unknown –attributes.1.name parameter
    […]

    I’m thinking it wants JSON instead of individually indexed array stuff, so I’ve tried things like –attributes='[{“slug”:”pa_city”,”value”:”Cityville”}]’ but I’ve been getting nowhere.

    Does anyone know how to create a product with attributes via the CLI?

    1. steve Avatar
      steve

      Ryan,

      Have you found any answer to your question? I’ve tried JSON too for –attributes, but it does not work well.

    2. xavaireland Avatar
      xavaireland

      I am trying to do the same thing and it does not work.


Stay in the Loop

1–4 emails per month. Unsubscribe anytime.

Discover more from BUT. Honestly

Subscribe now to keep reading and get access to the full archive.

Continue reading