إشعارات أكواد تتبع WooCommerce
إرسال SMS تلقائياً عند إضافة بوابات الشحن لأكواد التتبع إلى طلبات WooCommerce.
إشعار العملاء تلقائياً عبر SMS عند إضافة بوابات الشحن لأكواد التتبع إلى طلبات WooCommerce الخاصة بهم. هذا يقلل من استفسارات الدعم الفني ويبقي العملاء على اطلاع بشحناتهم.
كيف يعمل
- بوابة الشحن تعالج الشحنة وتضيف ملاحظة على الطلب تحتوي على كود التتبع
- WSMS يستمع للملاحظات الجديدة على الطلبات
- عندما تتطابق ملاحظة مع نمط كود التتبع، يرسل WSMS رسالة SMS للعميل
مثال على ملاحظة الطلب
عادةً ما تضيف بوابات الشحن ملاحظات بهذا التنسيق:
Tracking code: 123456789 (Carrier: DHL)
التنفيذ
أضف هذا الكود إلى ملف functions.php الخاص بالقالب أو إضافة مخصصة:
add_action('wp_insert_comment', 'wp_sms_handle_new_order_note', 10, 2);
function wp_sms_handle_new_order_note($comment_id, $comment_object) {
// Check if the comment is an order note
if ($comment_object->comment_type !== 'order_note') {
return;
}
// Get the note content
$note_content = $comment_object->comment_content;
// Check if the note contains tracking code
if (!preg_match('/Tracking code:/i', $note_content)) {
return;
}
// Get the order ID from the comment
$order_id = $comment_object->comment_post_ID;
// Get the customer's phone number from order
$customer_number = \WP_SMS\Helper::getWooCommerceCustomerNumberByOrderId($order_id);
// Check if a valid phone number exists
if (empty($customer_number)) {
return;
}
wp_sms_send(
$customer_number,
$note_content
);
}
التخصيص
تغيير النمط
عدّل نمط التعبير النمطي (regex) ليتطابق مع تنسيق بوابة الشحن الخاصة بك:
// For "Shipment ID:" format
if (!preg_match('/Shipment ID:/i', $note_content)) {
return;
}
// For multiple patterns
if (!preg_match('/Tracking code:|Shipment ID:|AWB:/i', $note_content)) {
return;
}
تنسيق رسالة مخصص
إرسال رسالة مخصصة بدلاً من ملاحظة الطلب الخام:
// Extract tracking number
preg_match('/Tracking code:\s*(\S+)/i', $note_content, $matches);
$tracking_number = $matches[1] ?? '';
$message = sprintf(
'Your order #%d has shipped! Track it: %s',
$order_id,
$tracking_number
);
wp_sms_send($customer_number, $message);
بوابات الشحن المتوافقة
يعمل هذا الحل مع أي بوابة شحن تضيف ملاحظات على الطلبات، بما في ذلك:
- OTO
- DHL
- FedEx
- UPS
- تكاملات شركات الشحن المحلية
ذو صلة
- wp_sms_send() - دالة إرسال رسائل SMS
آخر تحديث: ٢٣ ديسمبر ٢٠٢٤