/*
Plugin Name: sinozit-sms
*/
//ini_set('display_errors', 1);
add_action('woocommerce_order_status_processing', 'sinozit_store_invoice_data', 10, 1);
function sinozit_store_invoice_data($order_id) {
if (!$order_id) return;
$order = wc_get_order($order_id);
if (!$order) return;
$items_data = [];
$full_name = $order->get_formatted_billing_full_name();
$address_1 = $order->get_billing_address_1();
$address_2 = $order->get_billing_address_2();
$city = $order->get_billing_city();
$state = $order->get_billing_state();
$postcode = $order->get_billing_postcode();
$phone = $order->get_billing_phone();
$customer_note = $order->get_customer_note(); // توضیحات خریدار
// تنظیمات اولیه
$apiKey = '7469686775627349317A61756E736A6D6C54463334413D3D'; // کلید API شما
$customer_phone = sinozit_get_customer_mobile_from_order($order);
$receptor = $customer_phone; // شماره گیرنده
$token = $order_id; // کد تایید
$template = 'carstorcheckout'; // نام قالب تعریف شده در پنل
// آدرس نهایی API
$url = "https://api.kavenegar.com/v1/$apiKey/verify/lookup.json";
// دادههایی که باید ارسال شوند
$data = [
'receptor' => $receptor,//$receptor,
'token' => $token,
'template' => $template
];
// راهاندازی cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // تبدیل آرایه به فرمت فرم
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // در محیط لوکال این را true نگه دارید
// اجرای درخواست
$response = curl_exec($ch);
// بررسی خطاها
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// چاپ پاسخ سرور (به صورت JSON دریافت میشود)
$result = json_decode($response, true);
//print_r($result);
}
// بستن اتصال
curl_close($ch);
// دادههایی که باید ارسال شوند
$data = [
'receptor' => '09053669723',//$receptor,
'token' => $token,
'template' => $template
];
// راهاندازی cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // تبدیل آرایه به فرمت فرم
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // در محیط لوکال این را true نگه دارید
// اجرای درخواست
$response = curl_exec($ch);
// بررسی خطاها
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// چاپ پاسخ سرور (به صورت JSON دریافت میشود)
$result = json_decode($response, true);
//print_r($result);
}
// بستن اتصال
curl_close($ch);
// دادههایی که باید ارسال شوند
$data = [
'receptor' => '09114649088',//$receptor,
'token' => $token,
'template' => $template
];
// راهاندازی cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // تبدیل آرایه به فرمت فرم
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // در محیط لوکال این را true نگه دارید
// اجرای درخواست
$response = curl_exec($ch);
// بررسی خطاها
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// چاپ پاسخ سرور (به صورت JSON دریافت میشود)
$result = json_decode($response, true);
//print_r($result);
}
// بستن اتصال
curl_close($ch);
}
function sinozit_get_customer_mobile_from_order($order) {
// اولویت اول: تلفن Checkout
$phone = sinozit_normalize_iran_phone($order->get_billing_phone());
if ($phone) {
return $phone;
}
$user_id = $order->get_customer_id();
$phone = get_user_meta($user_id, 'aryabyte_otp_login_phone', true);
return $phone;
}
function sinozit_normalize_iran_phone($phone) {
return $phone;
if (empty($phone)) {
return false;
}
// تبدیل ارقام فارسی و عربی به انگلیسی
$phone = strtr((string) $phone, array(
'۰' => '0', '۱' => '1', '۲' => '2', '۳' => '3',
'۴' => '4', '۵' => '5', '۶' => '6', '۷' => '7',
'۸' => '8', '۹' => '9',
'٠' => '0', '١' => '1', '٢' => '2', '٣' => '3',
'٤' => '4', '٥' => '5', '٦' => '6', '٧' => '7',
'٨' => '8', '٩' => '9',
));
// حذف +، فاصله، خط تیره و سایر کاراکترهای غیر عددی
$phone = preg_replace('/\D+/', '', $phone);
// 0098xxxxxxxxxx => 0xxxxxxxxxx
if (strpos($phone, '0098') === 0) {
$phone = '0' . substr($phone, 4);
// 98xxxxxxxxxx => 0xxxxxxxxxx
} elseif (strpos($phone, '98') === 0) {
$phone = '0' . substr($phone, 2);
// 9xxxxxxxxx => 09xxxxxxxxx
} elseif (strpos($phone, '9') === 0 && strlen($phone) === 10) {
$phone = '0' . $phone;
}
// فقط شماره موبایل ایرانی 11 رقمی
return $phone;
}
Warning: Cannot modify header information - headers already sent by (output started at /var/www/carstor.ir/wp-content/plugins/trend-sms/index.php:1) in /var/www/carstor.ir/wp-includes/pluggable.php on line 1539
Warning: Cannot modify header information - headers already sent by (output started at /var/www/carstor.ir/wp-content/plugins/trend-sms/index.php:1) in /var/www/carstor.ir/wp-includes/pluggable.php on line 1542