This project is in a early alpha stage.
The aim is to develop a cli tool that can read a CSV file and alter all sort of WooCommerce product data (prices, stock quantities, meta data, ect..) taking care of all related side-effect (eg: update the stock status of the variable product if all its variations are out of stock).
- Import the project in your theme in a custom folder (eg: 'cli').
- Run a
composer installinside the project folder. - Require che
command.phpfile:<?php require_once 'cli/waga-woocommerce-csv-cli-importer/src/command.php';in yourfunctions.phpfile. - Now you should be able to call
wp wwc-prod-csv-import.
The script can import data from a CSV file. This file must have one product per row and a series of column with the data to update. The CSV headers (the first line) can be the default ones provided in the file docs/standard_headers.md or can be customized through a manifest file.
With a CSV (product-list.csv) formatted like that:
| SKU | meta:_regular_price | meta:_sale_price |
|---|---|---|
| woo-hoodie-red | 45 | 42 |
| woo-hoodie-blue-logo | 45 | |
| woo-hoodie-green | 45 | 38 |
| woo-hoodie-blue | 45 |
You can run: wp --allow-root wwc-prod-csv-import /path/to/product-list.csv to mass-update the listed products.
If you want (or forced to) use custom headers, like:
| Sku | Price | Sale Price |
|---|---|---|
| woo-hoodie-red | 45 | 42 |
| woo-hoodie-blue-logo | 45 | |
| woo-hoodie-green | 45 | 38 |
| woo-hoodie-blue | 45 |
You can create manifest file, eg: prices-import.json, like that:
{
"Price": "meta:_regular_price",
"Sale Price": "meta:_sale_price",
"Sku": "SKU",
"_types": {
"Price": "price",
"Sale Price": "price"
}
}
To map the headers to the default counterparts.
The _types field tells the script how to treat the data in the specified column. For now, only price is supported. price type will cast the data to float e store it in a optimal way for WooCommerce.
To use the manifest file run: wp --allow-root wwc-prod-csv-import /path/to/product-list.csv --manifest=/path/to/prices-import.json.