add_action('woocommerce_order_status_changed', 'smsIrWoocommerceOrder', 10, 3);
/**
* @param $orderID
* @param $oldStatus
* @param $newStatus
* @return void
*/
function smsIrWoocommerceOrder($orderID, $oldStatus, $newStatus)
{
if (get_option("sms_ir_woocommerce_order_admin_{$newStatus}_status")) {
$order = wc_get_order($orderID);
$orderItems = $order->get_items();
$adminMobile = get_option("sms_ir_info_admin");
$text = get_option("sms_ir_woocommerce_order_admin_{$newStatus}_text");
// گرفتن کد رهگیری از متای سفارش
$tracking_json = get_post_meta($orderID, '_vi_wot_order_item_tracking_data', true);
$tracking_code = '';
if ($tracking_json) {
$tracking_data = json_decode($tracking_json, true);
if (is_array($tracking_data) && isset($tracking_data[0]['tracking_number'])) {
$tracking_code = $tracking_data[0]['tracking_number'];
}
}
error_log("Tracking meta raw: " . print_r(get_post_meta($orderID, '_vi_wot_order_item_tracking_data', true), true));
if ($templateID = get_option("sms_ir_woocommerce_order_admin_{$newStatus}_template")) {
$price = number_format($order->get_total());
$shipping = number_format($order->get_shipping_total());
$discount = number_format($order->get_discount_total());
$items = "";
foreach ($orderItems as $item) {
$items .= $item->get_name() . " * " . $item->get_quantity() . PHP_EOL;
}
$itemsCount = count($orderItems);
$parameters = [
(object)[
"name" => "orderid",
"value" => "$orderID"
],
(object)[
"name" => "trackingcode",
"value" => $tracking_code // جایگزین order_key با کد رهگیری
],
(object)[
"name" => "description",
"value" => "{$order->get_customer_note()}"
],
(object)[
"name" => "paymentmethod",
"value" => "{$order->get_payment_method_title()}"
],
(object)[
"name" => "oldstatus",
"value" => "$oldStatus"
],
(object)[
"name" => "newstatus",
"value" => "$newStatus"
],
(object)[
"name" => "price",
"value" => "$price"
],
(object)[
"name" => "shipping",
"value" => "$shipping"
],
(object)[
"name" => "discount",
"value" => "$discount"
],
(object)[
"name" => "items",
"value" => "$items"
],
(object)[
"name" => "itemscount",
"value" => "$itemsCount"
],
(object)[
"name" => "productscount",
"value" => "{$order->get_item_count()}"
],
(object)[
"name" => "firstname",
"value" => "{$order->get_billing_first_name()}"
],
(object)[
"name" => "lastname",
"value" => "{$order->get_billing_last_name()}"
],
(object)[
"name" => "company",
"value" => "{$order->get_billing_company()}"
],
(object)[
"name" => "address1",
"value" => "{$order->get_billing_address_1()}"
],
(object)[
"name" => "address2",
"value" => "{$order->get_billing_address_2()}"
],
(object)[
"name" => "city",
"value" => "{$order->get_billing_city()}"
],
(object)[
"name" => "state",
"value" => "{$order->get_billing_state()}"
],
(object)[
"name" => "postcode",
"value" => "{$order->get_billing_postcode()}"
],
(object)[
"name" => "country",
"value" => "{$order->get_billing_country()}"
],
(object)[
"name" => "email",
"value" => "{$order->get_billing_email()}"
],
(object)[
"name" => "phone",
"value" => "{$order->get_billing_phone()}"
],
];
foreach (explode(",", get_option("sms_ir_woocommerce_order_admin_{$newStatus}_mobile")) as $mobile) {
SMSIRAppClass::sendVerifySMS($parameters, $templateID, "$mobile");
}
if ($adminMobile) {
SMSIRAppClass::sendVerifySMS($parameters, $templateID, "$adminMobile");
}
} else {
$mobiles = explode(',', get_option("sms_ir_woocommerce_order_admin_{$newStatus}_mobile"));
if ($adminMobile) {
$mobiles[] = $adminMobile;
}
$text = str_replace("#orderid#", $orderID, $text);
$text = str_replace("#newstatus#", $newStatus, $text);
$text = str_replace("#oldstatus#", $oldStatus, $text);
$text = str_replace("#trackingcode#", $tracking_code, $text);
$text = str_replace("#description#", $order->get_customer_note(), $text);
$text = str_replace("#paymentmethod#", $order->get_payment_method_title(), $text);
$text = str_replace("#price#", number_format($order->get_total()), $text);
$text = str_replace("#shipping#", number_format($order->get_shipping_total()), $text);
$text = str_replace("#discount#", number_format($order->get_discount_total()), $text);
$text = str_replace("#productscount#", $order->get_item_count(), $text);
$text = str_replace("#firstname#", $order->get_billing_first_name(), $text);
$text = str_replace("#lastname#", $order->get_billing_last_name(), $text);
$text = str_replace("#company#", $order->get_billing_company(), $text);
$text = str_replace("#address1#", $order->get_billing_address_1(), $text);
$text = str_replace("#address2#", $order->get_billing_address_2(), $text);
$text = str_replace("#city#", $order->get_billing_city(), $text);
$text = str_replace("#state#", $order->get_billing_state(), $text);
$text = str_replace("#postcode#", $order->get_billing_postcode(), $text);
$text = str_replace("#country#", $order->get_billing_country(), $text);
$text = str_replace("#email#", $order->get_billing_email(), $text);
$text = str_replace("#phone#", $order->get_billing_phone(), $text);
if (strpos($text, "#items#") !== false) {
$items = "";
foreach ($orderItems as $item) {
$items .= $item->get_name() . " * " . $item->get_quantity() . PHP_EOL;
}
$text = str_replace("#items#", $items, $text);
}
if (strpos($text, "#itemscount#") !== false) {
$text = str_replace("#itemscount#", count($orderItems), $text);
}
SMSIRAppClass::sendBulkSMS($text, $mobiles);
}
}
if (get_option("sms_ir_woocommerce_order_user_{$newStatus}_status")) {
$order = wc_get_order($orderID);
$orderItems = $order->get_items();
$adminMobile = get_option("sms_ir_info_admin");
$text = get_option("sms_ir_woocommerce_order_user_{$newStatus}_text");
// گرفتن کد رهگیری از متای سفارش
$tracking_json = get_post_meta($orderID, '_vi_wot_order_item_tracking_data', true);
$tracking_code = '';
if ($tracking_json) {
$tracking_data = json_decode($tracking_json, true);
if (is_array($tracking_data) && isset($tracking_data[0]['tracking_number'])) {
$tracking_code = $tracking_data[0]['tracking_number'];
}
}
if ($templateID = get_option("sms_ir_woocommerce_order_user_{$newStatus}_template")) {
$price = number_format($order->get_total());
$shipping = number_format($order->get_shipping_total());
$discount = number_format($order->get_discount_total());
$items = "";
foreach ($orderItems as $item) {
$items .= $item->get_name() . " * " . $item->get_quantity() . PHP_EOL;
}
$itemsCount = count($orderItems);
$parameters = [
(object)[
"name" => "orderid",
"value" => "$orderID"
],
(object)[
"name" => "trackingcode",
"value" => $tracking_code // جایگزین order_key با کد رهگیری
],
(object)[
"name" => "description",
"value" => "{$order->get_customer_note()}"
],
(object)[
"name" => "paymentmethod",
"value" => "{$order->get_payment_method_title()}"
],
(object)[
"name" => "oldstatus",
"value" => "$oldStatus"
],
(object)[
"name" => "newstatus",
"value" => "$newStatus"
],
(object)[
"name" => "price",
"value" => "$price"
],
(object)[
"name" => "shipping",
"value" => "$shipping"
],
(object)[
"name" => "discount",
"value" => "$discount"
],
(object)[
"name" => "items",
"value" => "$items"
],
(object)[
"name" => "itemscount",
"value" => "$itemsCount"
],
(object)[
"name" => "productscount",
"value" => "{$order->get_item_count()}"
],
(object)[
"name" => "firstname",
"value" => "{$order->get_billing_first_name()}"
],
(object)[
"name" => "lastname",
"value" => "{$order->get_billing_last_name()}"
],
(object)[
"name" => "company",
"value" => "{$order->get_billing_company()}"
],
(object)[
"name" => "address1",
"value" => "{$order->get_billing_address_1()}"
],
(object)[
"name" => "address2",
"value" => "{$order->get_billing_address_2()}"
],
(object)[
"name" => "city",
"value" => "{$order->get_billing_city()}"
],
(object)[
"name" => "state",
"value" => "{$order->get_billing_state()}"
],
(object)[
"name" => "postcode",
"value" => "{$order->get_billing_postcode()}"
],
(object)[
"name" => "country",
"value" => "{$order->get_billing_country()}"
],
(object)[
"name" => "email",
"value" => "{$order->get_billing_email()}"
],
(object)[
"name" => "phone",
"value" => "{$order->get_billing_phone()}"
],
];
SMSIRAppClass::sendVerifySMS($parameters, $templateID, "{$order->get_billing_phone()}");
} else {
$text = str_replace("#orderid#", $orderID, $text);
$text = str_replace("#newstatus#", $newStatus, $text);
$text = str_replace("#oldstatus#", $oldStatus, $text);
$text = str_replace("#trackingcode#", $tracking_code, $text);
$text = str_replace("#description#", $order->get_customer_note(), $text);
$text = str_replace("#paymentmethod#", $order->get_payment_method_title(), $text);
$text = str_replace("#price#", number_format($order->get_total()), $text);
$text = str_replace("#shipping#", number_format($order->get_shipping_total()), $text);
$text = str_replace("#discount#", number_format($order->get_discount_total()), $text);
$text = str_replace("#productscount#", $order->get_item_count(), $text);
$text = str_replace("#firstname#", $order->get_billing_first_name(), $text);
$text = str_replace("#lastname#", $order->get_billing_last_name(), $text);
$text = str_replace("#company#", $order->get_billing_company(), $text);
$text = str_replace("#address1#", $order->get_billing_address_1(), $text);
$text = str_replace("#address2#", $order->get_billing_address_2(), $text);
$text = str_replace("#city#", $order->get_billing_city(), $text);
$text = str_replace("#state#", $order->get_billing_state(), $text);
$text = str_replace("#postcode#", $order->get_billing_postcode(), $text);
$text = str_replace("#country#", $order->get_billing_country(), $text);
$text = str_replace("#email#", $order->get_billing_email(), $text);
$text = str_replace("#phone#", $order->get_billing_phone(), $text);
if (strpos($text, "#items#") !== false) {
$items = "";
foreach ($orderItems as $item) {
$items .= $item->get_name() . " * " . $item->get_quantity() . PHP_EOL;
}
$text = str_replace("#items#", $items, $text);
}
if (strpos($text, "#itemscount#") !== false) {
$text = str_replace("#itemscount#", count($orderItems), $text);
}
SMSIRAppClass::sendBulkSMS($text, ["{$order->get_billing_phone()}"]);
}
}
}
لانس دو نازله آلفا 55 سانتی - فروشگاه تیرافل
پرش به محتوا
دیدگاهها
هیچ دیدگاهی برای این محصول نوشته نشده است.