WP Manifestindependent plugin directory
manifest / users / similar-account-merger

Similar Account Merger

WordPress/WooCommerce plugin to detect and merge duplicate customer accounts — normalizes messy Iranian mobile phone formats (billing_phone / mw_user_phone) and safely merges phone-duplicate accounts (HPOS-compatible order transfer, reversible flag instead of delete).

by Your Name · github.com/hoseinrza/similar-account-merger

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/hoseinrza/similar-account-merger/archive/refs/heads/main.zip

Readme

Typing SVG



✨ What it does

Two review-first tools for cleaning up a WordPress/WooCommerce customer list, wrapped in one plugin. Nothing merges or deletes automatically — every action is a deliberate, admin-confirmed click.

🧭 Similar Account Merger

Users → Merge Accounts

Scores accounts by display-name similarity and email match, lists candidate pairs side by side, and reassigns content to the account you keep. The duplicate is flagged, never deleted.

📱 Phone Number Tools

WooCommerce → Phone Number Tools

Cleans up billing_phone / mw_user_phone into a single 09xxxxxxxxx format, then finds accounts that only look different because their phone number was formatted differently — and merges them.


🩹 Phone number normalization

Handles every messy format an Iranian mobile number shows up in, and sorts what it finds into two buckets:

+989123456789   ─┐
00989123456789   ├─▶  09123456789   ✅ auto-fixable
989123456789     │
9123456789       │
۰۹۱۲۳۴۵۶۷۸۹ (fa)  ┘

anything else  ──▶  🔎 flagged for manual review

The scan runs as a single REGEXP query straight against wp_usermeta — it never loads the full customer table into PHP just to check formats. A separate confirm step rewrites only the rows that came back broken.

🔗 Duplicate detection & merge

flowchart LR
    A[Scan wp_usermeta<br/>GROUP BY normalized phone] --> B{More than one<br/>account per number?}
    B -- yes --> C[Show one duplicate<br/>group at a time]
    C --> D[Admin picks the<br/>primary account]
    D --> E[Orders reassigned<br/>via WC CRUD · HPOS-safe]
    E --> F[Empty meta on primary<br/>backfilled from duplicate]
    F --> G[Duplicate flagged<br/>_tamland_merged_into<br/>+ email locked]
    G --> A
    B -- no --> H[✅ Nothing left to review]

Order counts per account come from one aggregate query (not a loop per customer), so this stays fast even with a few thousand accounts.


🛡️ Safety by design

Guarantee How
No accidental page-load queries Every scan/find/merge action runs only on an explicit, nonce-verified button click
No N+1 over the customer table Broken formats and duplicate groups are found with direct wpdb REGEXP / aggregate queries
No silent data loss Duplicates are flagged (_tamland_merged_into) and email-locked, never deleted — fully reversible
No unauthorized access Both admin pages require manage_woocommerce / promote_users, checked on menu and on render
HPOS-safe order transfer Orders move via wc_get_order()->set_customer_id()->save(), not raw SQL

🚀 Installation

  1. Copy the plugin folder into wp-content/plugins/
  2. Activate Similar Account Merger from the Plugins screen
  3. Find the tools under:
    • Users → Merge Accounts
    • WooCommerce → Phone Number Tools

🗂️ Structure

similar-account-merger.php     Plugin bootstrap
includes/
 ├─ class-sam-plugin.php       Loader
 ├─ class-sam-matcher.php      Name/email similarity scoring
 └─ class-sam-merger.php       Generic account merge
admin/
 ├─ class-sam-admin.php        "Merge Accounts" admin page
 └─ class-sam-phone-admin.php  "Phone Number Tools" admin page

Built for shops where the same customer signed up three times because their phone number looked different every time.

Read the full README on GitHub →