Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/asha-webtech-it-solutions/wp-woo-bulk-order-delete-cleaner-safe-php-bootstrap/archive/refs/heads/main.zip=========================================================================================== WooCommerce Safe Order Cleaner Version: 1.0.0 Author: Asha WebTech IT Solutions Pvt Ltd
INSTALLATION
- Upload the
safe-order-cleanerfolder to /wp-content/plugins/ - Activate the plugin via WordPress → Plugins
- Go to Tools → WC Order Cleaner
- Run Diagnostics tab first to confirm detection is correct
- Take a full database backup before any deletions
RECOMMENDED ROLLOUT
Stage 1: Install → run Diagnostics → confirm tables detected correctly Stage 2: Create a job with tight filters → dry run → review output Stage 3: Delete 10 test orders → verify website Stage 4: Delete 100 orders → verify website Stage 5: Run larger batch deletion
=========================================================================================== DATABASE TABLES (plugin-owned only)
{prefix}soc_jobs id BIGINT UNSIGNED — Primary key job_key VARCHAR(40) — Human-readable ID e.g. SOC-20260810-001 user_id BIGINT UNSIGNED — WordPress user who created the job status VARCHAR(20) — pending|scanning|dry_run|running|paused|cancelled|completed|failed filters LONGTEXT — JSON-encoded filter configuration (immutable once job starts) mode VARCHAR(20) — 'permanent' or 'trash' is_dry_run TINYINT(1) — 1 = dry run job batch_size SMALLINT — Orders per batch (10–100) total_orders INT UNSIGNED — Count set at scan time max_order_id INT UNSIGNED — Ceiling ID set at scan time (prevents new orders being caught) processed INT UNSIGNED — Running total of orders attempted deleted_count INT UNSIGNED — Successfully deleted failed_count INT UNSIGNED — Failed to delete skipped_count INT UNSIGNED — Skipped (already gone, excluded, etc.) last_processed_id BIGINT UNSIGNED — Cursor for resumable batching (WHERE id > this) error_info TEXT — Last critical error created_at DATETIME UTC — Job creation timestamp started_at DATETIME UTC — When deletion/dry-run began completed_at DATETIME UTC — When job finished/cancelled
{prefix}soc_logs id BIGINT UNSIGNED — Primary key job_id BIGINT UNSIGNED — FK to soc_jobs.id order_id BIGINT UNSIGNED — WooCommerce order ID result VARCHAR(20) — success|failed|skipped|dry_run error_message TEXT — Error detail (truncated to 1000 chars) created_at DATETIME UTC — Log entry timestamp
NOTE: Customer PII (name, email, address) is NEVER stored in these tables.
=========================================================================================== HPOS COMPATIBILITY
Storage detection is automatic at runtime via: \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled()
Current site configuration (detected from your screenshot):
- Legacy WordPress Posts (wp_posts) — AUTHORITATIVE
- HPOS compatibility sync mode — ENABLED
- This means orders exist in BOTH wp_posts AND wc_orders tables
Deletion is done exclusively via: wc_get_order($id)->delete(true)
WooCommerce's own data store handles cleanup in both legacy and HPOS tables. The plugin NEVER runs raw DELETE SQL against order data.
The plugin declares HPOS compatibility via FeaturesUtil so WooCommerce does not flag it as incompatible.
=========================================================================================== DELETION MECHANISM — EXACTLY WHAT HAPPENS
For each order:
- wc_get_order($order_id) — verify it exists and is a shop_order
- Check soc_before_delete_order filter — allow third-party blocking
- $order->delete(true) — permanent deletion via WooCommerce CRUD
WooCommerce internally fires these hooks:
- woocommerce_delete_order
- before_delete_post
- after_delete_post (legacy)
- Various WooCommerce data store cleanup actions
The following are cleaned up BY WOOCOMMERCE (not by this plugin):
- wp_posts record
- wp_postmeta records
- woocommerce_order_items rows
- woocommerce_order_itemmeta rows
- wc_orders row (HPOS, if sync enabled)
- wc_order_addresses rows
- wc_order_operational_data row
- wc_orders_meta rows
- wc_order_stats row
- wc_order_product_lookup rows
- wc_download_log rows
=========================================================================================== THIRD-PARTY PLUGIN HANDLING (Fresh Farmse specific)
FF Stock Reduction on Completion (ff-stock-reduction-on-completion): AUTOMATIC: The plugin's delete_guard() function hooks into woocommerce_delete_order and before_delete_post. When our code calls $order->delete(true), WooCommerce fires these hooks, FF Stock's delete_guard() runs, checks _ff_stock_reduced meta, and if 'yes' — restores product stock automatically. ACTION: Nothing special required. Stock restoration is correctly automatic. REPORTED IN DRY RUN: "FF Stock will be restored on deletion" per order.
FF Inventory Manager (ff-stock-manager): The ffsm_logs table is a product-level stock audit log with no direct foreign key to WooCommerce orders. Deleting orders does not affect this table. ACTION: No action taken. No records affected.
TeraWallet (woo-wallet): Tables: {base_prefix}woo_wallet_transactions and {base_prefix}woo_wallet_transaction_meta These are FINANCIAL RECORDS and must NOT be automatically deleted. Detected via: payment_method = 'woo-wallet', partial payment fee items, and woo_wallet_transaction_meta.meta_key = 'order_id' ACTION: Detect, warn in dry run, DO NOT delete. TeraWallet records remain intact.
WC Business Intelligence (wc-business-intelligence): Current version does not use custom tables. Reads from WC analytics tables (wc_order_stats, wc_order_product_lookup) which WooCommerce cleans on deletion. ACTION: No special handling needed.
WooCommerce Attribute Stock (woocommerce-attribute-stock): Attribute stock is managed at product level. FF Stock Reduction handles stock restoration via its delete_guard() hook. ACTION: No special handling needed.
Advanced Order Export: No database records — export-only plugin. ACTION: No action needed.
Custom Order Status for WooCommerce: Custom statuses are dynamically fetched via wc_get_order_statuses() so all custom statuses appear in the filter UI automatically. Note: This plugin is flagged as HPOS-incompatible by WooCommerce. Since the site uses legacy storage, this does not affect our plugin's operation.
=========================================================================================== SECURITY REVIEW
Authentication: All AJAX handlers call SOC_Security::verify_ajax_request() which checks is_user_logged_in(), current_user_can('manage_woocommerce_order_cleanup'), and wp_verify_nonce() before any processing.
Capability: Uses a dedicated 'manage_woocommerce_order_cleanup' capability added to administrator role on activation. Does NOT rely solely on manage_options.
CSRF: wp_create_nonce() / wp_verify_nonce() on every request. Action: 'soc_admin'.
SQL Injection: All user inputs go through $wpdb->prepare() with typed placeholders (%d, %s, %f). No string concatenation of user values into SQL.
Input sanitization: All inputs sanitized via sanitize_text_field(), sanitize_email(), absint(), (float) casts as appropriate before use.
Destructive confirmation: Three checkboxes + typed phrase "DELETE N ORDERS" required before permanent deletion can start.
Race condition prevention: SOC_Job_Manager::get_active_job() checked before starting any new job. Only one job can be in running/scanning/dry_run status at a time.
=========================================================================================== PERFORMANCE REVIEW
Scanning: Uses direct SQL (ID-only, no full row fetches) against wp_posts or wc_orders. Index-friendly queries — ID, post_type, post_status, post_date are all indexed.
Batching: Cursor-based pagination (WHERE id > last_id ORDER BY id ASC LIMIT N). Avoids OFFSET on large datasets — no slow full-table scans.
Batch size: Default 50 orders/batch. Max 100. Each batch finishes in seconds.
Background: Action Scheduler (bundled with WooCommerce) runs batches independently of the browser. Immune to PHP timeout, browser close, or internet disconnect.
Memory: Only batch_size order objects loaded into memory at any time. For 50 orders: minimal memory footprint.
Preview: Pagination with 20 orders/page. wc_get_order() called per visible row only.
Third-party detection: Batch SQL queries for the entire batch at once. Single query for TeraWallet, single query for FF Stock — not per-order queries.
=========================================================================================== TESTING CHECKLIST
Before production: [ ] Take full database backup [ ] Run Diagnostics tab — confirm all tables detected [ ] Confirm HPOS mode matches expectations [ ] Run dry run on 10 test orders — verify output [ ] Delete 10 test orders — verify WooCommerce admin, inventory, wallet [ ] Restore backup — verify all data intact [ ] Delete 100 orders — verify performance [ ] Test browser close during deletion — reopen and confirm job paused/resumed [ ] Test Pause / Resume cycle [ ] Test Cancel — confirm no additional orders deleted [ ] Test Emergency Stop [ ] Test with an order that has _ff_stock_reduced = yes — confirm stock restored [ ] Test with a TeraWallet order — confirm wallet records intact after deletion [ ] Test with custom order statuses — confirm they appear in filter UI [ ] Test Retry Failed [ ] Test Job History display [ ] Test Log viewer with result filter [ ] Confirm soc_logs table does not grow unboundedly (check pruning cron)
=========================================================================================== KNOWN LIMITATIONS
-
TeraWallet records are NOT automatically deleted. This is intentional — they are financial records. Manual cleanup requires direct database work after verification.
-
ff_stock_log entries are NOT deleted when orders are deleted. These are audit records of historical stock changes. They remain as a historical log.
-
Orders with a status of 'trash' in wp_posts are NOT automatically included in scans unless you explicitly add 'trash' to the status filter.
-
Very large terawallet or postmeta tables may cause the third-party detection queries to be slow. This only affects dry-run reporting, not the deletion speed.
-
The preview page calls wc_get_order() per order for display — this is intentionally accurate but slower than raw SQL. The preview is for verification, not bulk ops.
-
If Action Scheduler's queue is very busy, there may be a delay before each batch starts. This is expected and safe — it does not affect resumability.
-
WooCommerce subscription parent orders: if you delete a subscription's parent order, child renewal orders may be orphaned. Exclude subscription orders if applicable.
=========================================================================================== ROLLBACK / BACKUP INSTRUCTIONS
The plugin does not create backups. Use a dedicated backup solution.
Recommended backup approach: Option A: Hostinger's database backup tool (available in hPanel) Option B: phpMyAdmin → Export → SQL → gzip Option C: WP plugin: All-in-One WP Migration or UpdraftPlus Option D: Server mysqldump: mysqldump -u USER -p DBNAME > backup.sql
After restoration:
- Import SQL backup via phpMyAdmin or mysql CLI
- Clear WooCommerce analytics cache: WooCommerce → Status → Tools → Clear transients
- Verify orders appear in WooCommerce admin
- Verify inventory levels
- Verify TeraWallet balances
- Place a test order end-to-end
=========================================================================================== UNINSTALL BEHAVIOUR
Deactivation: Running jobs are set to 'paused'. No data deleted.
Uninstall (with "Delete data on uninstall" DISABLED — DEFAULT): Nothing is deleted. Tables and settings remain.
Uninstall (with "Delete data on uninstall" ENABLED): Removed: soc_jobs table, soc_logs table, soc_settings option, soc_db_version option NOT removed: Any WooCommerce orders, products, customers, or any WC data.
=========================================================================================== CHANGELOG
1.0.0 — 2026-08-10 Initial release
- Cursor-based batch deletion via Action Scheduler
- Full HPOS + legacy storage compatibility
- TeraWallet detection (no auto-delete)
- FF Stock Reduction hook integration
- Dry run with third-party data reporting
- Typed confirmation + checkbox gate
- Pause / Resume / Cancel / Emergency Stop
- Retry failed orders
- Job history + paginated log viewer
- Diagnostics page with table detection
- Configurable batch size, min age, log retention