Is it possible to create, update products bulk through command line WP-CLI WC-LI?

Viewed 680

I am developing a motorbike parts ecommerce with Wordpress/Woocomerce.

I find a lot of problems because my bussiness requieres very deep tree category products (brand > model > engine > version > year), and there are many registers for that! (more than 62.000 rows, ID categories...)

So, I am using WP-CLI WC-CLI command line for deal with that.

I know how to create one product through command line:

wp wc product create --name="product name" --sku=001 --user=admin

I even know how to create many products in the same command line:

wp wc product create --name="product name" --sku=001 --user=admin | wp wc product create --name="product name 2" --sku=002 --user=admin | (and so on)


But, my question is:

May I create/update thousands of products with just one line in my terminal?

Something like this:

wp wc product create --name='[{"name"=product name 3},{"name"=product name 4},{"name"=product name 5}]' --sku=003 --user=admin

I saw, that kind of json format works for assigning to the same product many categories:

--categories='[{"id"=21},{"id"=22}]

If that is not possible, is it possible to run some terminal/command line script to throw this single lines as loop with some timeout?

In advance, thanks a lot!

1 Answers

So what you can do is export your product from word press back end which will give you an XML file which gives you the fields you need to create your own xml file with your product list. Then simply save that xml file into the root directory of your site and run the following wp-cli command: WP IMPORT yourfilename.xml authors=skip. It will upload your new products and much faster than through the back end wp interface.

Related