Skip to main content

WordPress Batch Import Guide

Comprehensive guide for the WordPress batch import orchestrator script.

Overview

The wp-batch-import.sh script is a master orchestrator that manages the complete WordPress product import workflow with safety checks, rollback capability, and detailed reporting.

Features

  • Safety First: Automatic backups before any changes
  • Interactive Mode: Step-by-step confirmations
  • Dry-Run Mode: Test without making actual changes
  • Rollback Capability: Restore from backups if needed
  • Progress Tracking: Real-time progress with ETA
  • Detailed Logging: Console and file logging
  • Email Notifications: Optional email reports
  • Error Handling: Comprehensive error handling and recovery

Prerequisites

  • WP-CLI installed
  • Node.js and npm
  • WordPress installation
  • WooCommerce REST API keys
  • CSV product file

Installation

  1. Clone or download scripts to /scripts/ directory:
  1. Configure environment in .env file:

Quick Start

Basic Usage

Configuration Helper

Workflow Steps

The script executes the following steps in order:

1. Pre-check

  • Verify WP-CLI installation
  • Check WordPress path
  • Validate CSV file
  • Test database connection
  • Check required dependencies

2. Backup

  • Export WordPress database
  • Backup uploads metadata
  • Store backup with timestamp
  • Save backup location for rollback

3. Download Images

  • Extract image URLs from CSV
  • Download images to temp directory
  • Skip existing images
  • Track download statistics

4. Generate SEO Content

  • Analyze product data
  • Generate meta descriptions
  • Create SEO-friendly titles
  • Optimize product descriptions

5. Update Products

  • Match existing products by SKU
  • Update product metadata
  • Update prices and stock
  • Preserve existing data

6. Create Products

  • Create new product posts
  • Set product categories
  • Assign product attributes
  • Link product images

7. Verify Import

  • Count imported products
  • Validate product data
  • Check for errors
  • Generate import report

Command Line Options

Environment Variables

Examples

Production Import

Skip Image Downloads

Custom Configuration

Output and Logs

Console Output

The script provides colored console output:
  • 🟢 Green: Success messages
  • 🔴 Red: Error messages
  • 🟡 Yellow: Warnings
  • 🔵 Blue: Information
  • 🟣 Purple: Debug messages

Log Files

Logs are saved to /logs/ directory:

Statistics Report

The final report includes:
  • Products processed/updated/created/failed
  • Images downloaded/failed
  • Total errors
  • Execution time
  • Backup location

Rollback

If the import fails or you need to undo changes:

Troubleshooting

WP-CLI Not Found

Permission Denied

Database Connection Error

Image Download Failures

WooCommerce API Errors

CSV File Format

Expected CSV structure:

Best Practices

  1. Always test with dry-run first
  2. Keep regular backups
  3. Monitor logs for errors
  4. Verify imports in WordPress admin
  5. Use non-interactive mode for automation
  6. Enable email notifications for production
  7. Keep CSV file validated and clean

Automation

Cron Job

CI/CD Pipeline

Support

For issues or questions:
  • Check log files in /logs/
  • Review configuration with wp-import-config.sh validate
  • Test with --dry-run first
  • Check WordPress and WooCommerce requirements

License

MIT License - See project root for details.