WooCommerce Order Billing Profile Sync
Synchronizes registered customer profiles with billing information from saved WooCommerce orders.
by Amirreza Shayesteh Far · github.com/amirrezashf/woocommerce-order-billing-profile-sync · website
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/amirrezashf/woocommerce-order-billing-profile-sync/archive/refs/heads/main.zipSynchronize registered customer profiles with billing information from saved WooCommerce orders.
Description
WooCommerce stores billing data both on individual orders and in customer user metadata. These values may become inconsistent after checkout, administrative edits, migrations, or third-party integrations.
WooCommerce Order Billing Profile Sync uses the final billing information from a saved order to update the linked registered customer's WordPress profile and WooCommerce billing metadata.
Guest orders are ignored because they are not linked to a WordPress user account.
Features
- Synchronizes billing data after WooCommerce saves an order
- Updates WordPress
first_name - Updates WordPress
last_name - Updates WordPress
display_name - Updates standard WooCommerce billing metadata
- Includes billing company and both address lines
- Supports billing city, postcode, country, state, phone, and email
- Skips guest orders
- Skips deleted or invalid users
- Prevents duplicate execution in the same request
- Prevents recursive synchronization
- Does not overwrite valid profile data with empty values by default
- Avoids unnecessary writes when values are unchanged
- Sanitizes all synchronized values
- Handles
wp_update_user()errors - Supports WooCommerce HPOS
- Provides filters and action hooks
- Uses a single PHP file
- Creates no custom database tables
How It Works
The plugin runs on:
woocommerce_after_order_object_save
The synchronization flow is:
- Validate the saved object as a
WC_Order. - Confirm that the order belongs to a registered user.
- Sanitize billing fields.
- Update WordPress profile names.
- Compare and update WooCommerce billing user metadata.
- Fire a completion action.
The plugin processes each order only once per request.
Synchronized Profile Fields
first_name
last_name
display_name
display_name is built from the billing first and last name.
If the names are empty, the existing display name is preserved.
Synchronized Billing Metadata
billing_first_name
billing_last_name
billing_company
billing_address_1
billing_address_2
billing_city
billing_postcode
billing_country
billing_state
billing_phone
billing_email
Empty Value Protection
Empty order values do not erase existing user metadata by default.
This prevents incomplete orders from deleting valid saved customer information.
To allow empty values to remove existing metadata:
add_filter( 'wc_obps_allow_empty_values', '__return_true' );
Use this carefully.
What Is Not Changed
The plugin does not update:
- WordPress username
- Password
- Roles or capabilities
- WordPress account email
- Shipping address
- Order status
- Payment data
- Order items
Only WooCommerce billing_email metadata is synchronized. The WordPress user_email field remains unchanged.
Data Storage
The plugin creates no custom storage.
It updates existing WordPress user fields and standard WooCommerce user metadata.
No custom tables, options, transients, logs, or scheduled tasks are created.
Requirements
- PHP 7.4+
- WordPress 6.0+
- WooCommerce
- Orders linked to registered users
Installation
- Download the repository as ZIP.
- Open Plugins → Add New Plugin → Upload Plugin.
- Upload the ZIP.
- Install and activate the plugin.
No settings page is required.
Usage
After activation, synchronization is automatic whenever a linked WooCommerce order is saved.
This includes:
- New registered-customer orders
- Administrative order edits
- Compatible programmatic order saves
HPOS Compatibility
The plugin declares compatibility with WooCommerce High-Performance Order Storage.
It uses WooCommerce order objects and does not access order tables directly.
Security
- Direct file access protection
- WooCommerce order-object validation
- Registered-user validation
- Input sanitization
- No public AJAX endpoint
- No custom REST endpoint
- No direct SQL queries
- No password, role, or capability changes
- No external requests
Performance
- No frontend assets
- No settings page
- No external API calls
- No direct database queries
- Skips unchanged metadata
- Processes each order once per request
- Uses no persistent lock
Filters
wc_obps_should_sync_order
Prevent synchronization for selected orders:
add_filter(
'wc_obps_should_sync_order',
static function ( $should_sync, $order, $user_id ) {
if ( 'cancelled' === $order->get_status() ) {
return false;
}
return $should_sync;
},
10,
3
);
wc_obps_billing_data
Modify billing data before synchronization:
add_filter(
'wc_obps_billing_data',
static function ( $data, $order ) {
$data['billing_phone'] = preg_replace(
'/[^0-9+]/',
'',
$data['billing_phone']
);
return $data;
},
10,
2
);
wc_obps_user_update_data
Modify fields sent to wp_update_user():
add_filter(
'wc_obps_user_update_data',
static function ( $user_data ) {
unset( $user_data['display_name'] );
return $user_data;
}
);
wc_obps_billing_meta_keys
Limit synchronized metadata:
add_filter(
'wc_obps_billing_meta_keys',
static function () {
return array(
'billing_first_name',
'billing_last_name',
'billing_phone',
);
}
);
Actions
wc_obps_profile_synced
Runs after synchronization:
add_action(
'wc_obps_profile_synced',
static function ( $user_id, $order_id, $billing_data, $order ) {
// Optional integration.
},
10,
4
);
wc_obps_profile_sync_error
Runs when wp_update_user() returns an error:
add_action(
'wc_obps_profile_sync_error',
static function ( $error, $user_id, $order_id ) {
error_log( $error->get_error_message() );
},
10,
3
);
Operational Considerations
This plugin treats saved order billing data as an authoritative source for the linked customer profile.
This may be inappropriate when:
- Orders use one-time billing addresses
- Orders are placed for other people
- Shared company accounts are used
- Historical orders are edited
- Imported orders contain outdated data
- Migrations re-save old orders
Use wc_obps_should_sync_order to exclude those workflows.
Changelog
1.0.0
- Initial release
- Added profile-name synchronization
- Added WooCommerce billing-meta synchronization
- Added empty-value protection
- Added duplicate and recursive execution protection
- Added change detection
- Added HPOS compatibility
- Added filters and actions
License
GPL-3.0
Author
Amirreza Shayesteh Far
- Website: https://amirrezaa.ir/
- GitHub: https://github.com/amirrezashf
- Repository: https://github.com/amirrezashf/WooCommerce-Order-Billing-Profile-Sync
همگامسازی صورتحساب سفارش با پروفایل مشتری
همگامسازی پروفایل کاربران ثبتنامشده با اطلاعات صورتحساب سفارشهای ذخیرهشده ووکامرس.
توضیحات
ووکامرس اطلاعات صورتحساب را هم روی سفارش و هم در user meta مشتری نگهداری میکند. این اطلاعات ممکن است پس از checkout، ویرایش سفارش توسط مدیر، مهاجرت داده یا اجرای integrationهای دیگر با یکدیگر متفاوت شوند.
این افزونه اطلاعات نهایی صورتحساب سفارش ذخیرهشده را با پروفایل وردپرس و متادیتای صورتحساب حساب کاربری مرتبط همگام میکند.
سفارشهای مهمان نادیده گرفته میشوند.
قابلیتها
- اجرای خودکار پس از ذخیره سفارش
- بروزرسانی نام و نام خانوادگی وردپرس
- بروزرسانی نام نمایشی
- بروزرسانی متادیتای صورتحساب ووکامرس
- پشتیبانی از شرکت و دو خط آدرس
- پشتیبانی از شهر، استان، کشور و کد پستی
- پشتیبانی از موبایل و ایمیل صورتحساب
- نادیده گرفتن سفارش مهمان
- نادیده گرفتن کاربران حذفشده
- جلوگیری از اجرای تکراری
- جلوگیری از حلقه بازگشتی
- محافظت از دادههای معتبر در برابر مقادیر خالی
- عدم write برای مقدار بدون تغییر
- پاکسازی تمام دادهها
- مدیریت خطای
wp_update_user() - سازگاری با HPOS
- بدون جدول اختصاصی
- ساختار تکفایلی
نحوه عملکرد
افزونه روی Hook زیر اجرا میشود:
woocommerce_after_order_object_save
مراحل اجرا:
- اعتبارسنجی
WC_Order - دریافت شناسه کاربر مرتبط
- پاکسازی اطلاعات صورتحساب
- بروزرسانی اطلاعات اصلی پروفایل
- مقایسه و بروزرسانی user meta
- اجرای Action نهایی
هر سفارش در هر request فقط یک بار پردازش میشود.
فیلدهای پروفایل
first_name
last_name
display_name
اگر نام و نام خانوادگی خالی باشند، نام نمایشی موجود حذف نمیشود.
فیلدهای صورتحساب
billing_first_name
billing_last_name
billing_company
billing_address_1
billing_address_2
billing_city
billing_postcode
billing_country
billing_state
billing_phone
billing_email
محافظت از مقادیر خالی
بهصورت پیشفرض، مقدار خالی سفارش اطلاعات معتبر حساب را حذف نمیکند.
برای اجازه حذف با مقادیر خالی:
add_filter( 'wc_obps_allow_empty_values', '__return_true' );
این گزینه باید با احتیاط استفاده شود.
مواردی که تغییر نمیکنند
- نام کاربری
- رمز عبور
- نقش و capability
- ایمیل اصلی حساب وردپرس
- آدرس ارسال
- وضعیت سفارش
- اطلاعات پرداخت
- آیتمهای سفارش
فقط billing_email همگام میشود و user_email تغییر نمیکند.
ذخیرهسازی داده
افزونه ساختار جدیدی ایجاد نمیکند.
فقط اطلاعات موجود وردپرس و متادیتای استاندارد ووکامرس را بروزرسانی میکند.
جدول، option، transient، log یا Cron ساخته نمیشود.
پیشنیازها
- PHP 7.4+
- WordPress 6.0+
- WooCommerce
- سفارش متصل به کاربر ثبتنامشده
نصب
- repository را بهصورت ZIP دانلود کنید.
- وارد افزونهها ← افزودن افزونه تازه ← بارگذاری افزونه شوید.
- فایل ZIP را بارگذاری کنید.
- افزونه را نصب و فعال کنید.
صفحه تنظیمات وجود ندارد.
استفاده
پس از فعالسازی، همگامسازی بهصورت خودکار هنگام ذخیره سفارش انجام میشود.
این رفتار شامل موارد زیر است:
- سفارش جدید کاربر ثبتنامشده
- ویرایش سفارش توسط مدیر
- ذخیره programmatic سازگار
سازگاری با HPOS
افزونه سازگاری خود را با WooCommerce High-Performance Order Storage اعلام میکند.
هیچ دسترسی مستقیمی به جدول سفارشها ندارد.
امنیت
- جلوگیری از اجرای مستقیم فایل
- اعتبارسنجی order object
- اعتبارسنجی کاربر مرتبط
- پاکسازی دادهها
- بدون AJAX عمومی
- بدون REST API اختصاصی
- بدون SQL مستقیم
- بدون تغییر رمز، نقش یا capability
- بدون درخواست خارجی
عملکرد
- بدون CSS و JavaScript
- بدون صفحه تنظیمات
- بدون API خارجی
- بدون Query اختصاصی
- عدم بروزرسانی مقدار بدون تغییر
- یک اجرا برای هر سفارش در هر request
- بدون lock دائمی
فیلترها
wc_obps_should_sync_order
جلوگیری از همگامسازی برخی سفارشها:
add_filter(
'wc_obps_should_sync_order',
static function ( $should_sync, $order, $user_id ) {
if ( 'cancelled' === $order->get_status() ) {
return false;
}
return $should_sync;
},
10,
3
);
wc_obps_billing_data
تغییر اطلاعات پیش از همگامسازی:
add_filter(
'wc_obps_billing_data',
static function ( $data, $order ) {
$data['billing_phone'] = preg_replace(
'/[^0-9+]/',
'',
$data['billing_phone']
);
return $data;
},
10,
2
);
wc_obps_user_update_data
تغییر اطلاعات ارسالشده به wp_update_user():
add_filter(
'wc_obps_user_update_data',
static function ( $user_data ) {
unset( $user_data['display_name'] );
return $user_data;
}
);
wc_obps_billing_meta_keys
محدود کردن فیلدهای همگامشونده:
add_filter(
'wc_obps_billing_meta_keys',
static function () {
return array(
'billing_first_name',
'billing_last_name',
'billing_phone',
);
}
);
اکشنها
wc_obps_profile_synced
پس از همگامسازی اجرا میشود:
add_action(
'wc_obps_profile_synced',
static function ( $user_id, $order_id, $billing_data, $order ) {
// اتصال سفارشی.
},
10,
4
);
wc_obps_profile_sync_error
هنگام خطای بروزرسانی پروفایل اجرا میشود:
add_action(
'wc_obps_profile_sync_error',
static function ( $error, $user_id, $order_id ) {
error_log( $error->get_error_message() );
},
10,
3
);
ملاحظات عملیاتی
افزونه اطلاعات صورتحساب سفارش را منبع معتبر پروفایل در نظر میگیرد.
این رفتار ممکن است در شرایط زیر مناسب نباشد:
- آدرس یکبارمصرف
- سفارش برای شخص دیگر
- حساب سازمانی مشترک
- ویرایش سفارش قدیمی
- import داده قدیمی
- ذخیره مجدد سفارشها در migration
برای حذف این موارد از Filter wc_obps_should_sync_order استفاده کنید.
تغییرات نسخهها
1.0.0
- انتشار اولیه
- همگامسازی نام پروفایل
- همگامسازی metadata صورتحساب
- محافظت از مقادیر خالی
- جلوگیری از اجرای تکراری و بازگشتی
- تشخیص مقدار بدون تغییر
- سازگاری با HPOS
- افزودن Filterها و Actionها
مجوز
GPL-3.0
نویسنده
Amirreza Shayesteh Far
- وبسایت: https://amirrezaa.ir/
- گیتهاب: https://github.com/amirrezashf
- مخزن افزونه: https://github.com/amirrezashf/WooCommerce-Order-Billing-Profile-Sync