This project contains scripts to manage products, categories, and tags in a WooCommerce store. It allows you to extract data, upload it back to the store, and create backups of the data.
- Extract all product data from a WooCommerce store and save it to a CSV file.
- Extract product categories and tags and save them to CSV files.
- Automatically create timestamped backups of the CSV files for added security.
- Set backup files to read-only to prevent accidental deletion or modification.
- Upload product data, categories, and tags to the WooCommerce store.
- Restore data from specific backup files.
- Interactive menu to manage data extraction, upload, and restore backups.
- Python 3.x
- Virtual environment (recommended)
-
Clone the repository:
git clone https://github.com/JMViJi/woocommerce-product-manager.git cd woocommerce-product-manager
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.env
file with your WooCommerce credentials:WOO_URL=https://yourstore.com/wp-json/ CONSUMER_KEY=your_consumer_key CONSUMER_SECRET=your_consumer_secret
To obtain the API keys for your WooCommerce store, follow these steps:
- Log in to your WooCommerce store's WordPress admin dashboard.
- Go to WooCommerce > Settings.
- Click on the Advanced tab, then select REST API.
- Click the Add Key button.
- Fill in the Description (e.g., "Product Manager Script").
- Select the User you want to generate the key for in the User field.
- Set Permissions to Read/Write.
- Click the Generate API Key button.
- You will be shown a Consumer Key and a Consumer Secret. Copy these keys and paste them into your
.env
file asCONSUMER_KEY
andCONSUMER_SECRET
, respectively.
This script fetches all product data from the WooCommerce store, saves it to a CSV file, and creates a timestamped backup of the CSV file.
python src/extract.py
This script uploads product data, categories, or tags to the WooCommerce store.
python src/upload.py [products|categories|tags]
Restore a backup of the product data, categories, or tags.
python src/restore.py
- Fetch Product Data: The script connects to the WooCommerce API and retrieves all product data.
- Save to CSV: The fetched product data is saved to
data/products.csv
. - Create Backup: A timestamped backup of the CSV file is created in the
data/backups/products/
directory. The backup file is namedproducts_backup_YYYYMMDD_HHMMSS.csv
and is set to read-only to prevent accidental deletion or modification.
- Upload Products: This script uploads product data to the WooCommerce store. It reads product data from
data/products.csv
and uses the WooCommerce API to update the store. - Upload Categories: This script uploads category data to the WooCommerce store. It reads category data from
data/categories.csv
and uses the WooCommerce API to update the store. - Upload Tags: This script uploads tag data to the WooCommerce store. It reads tag data from
data/tags.csv
and uses the WooCommerce API to update the store.
- Restore Backup: This script allows you to restore data from specific backup files. You can choose to restore products, categories, or tags from their respective backups.
woocommerce-product-manager/
│
├───src/
│ ├───backup.py
│ ├───config.py
│ ├───extract.py
│ ├───upload.py
│ ├───restore.py
│ ├───utils.py
│ └───__pycache__/
│
├───data/
│ ├───backups/
│ │ ├───categories/
│ │ ├───products/
│ │ └───tags/
│ ├───categories.csv
│ ├───products.csv
│ └───tags.csv
│
├───.gitignore
├───main.py
├───README.md
├───requirements.txt
└───.env