/** * Plugin Name: WooCommerce Telegram 배송완료 알림 (Multi-Site) * Description: empresskorea.com, stylemz.com, skinseoulshop.com 주문이 배송 완료되면 Telegram으로 Fulfilled 메시지를 전송합니다. * Version: 1.2 * Author: Empress Korea */ if (!defined('ABSPATH')) exit; add_action('woocommerce_order_status_completed', 'ek_send_fulfilled_telegram_message_multisite'); function ek_send_fulfilled_telegram_message_multisite($order_id) { $order = wc_get_order($order_id); if (!$order) return; // ✅ 사이트 도메인 분기 $host = $_SERVER['HTTP_HOST'] ?? ''; $site_map = [ 'empresskorea.com' => ['name' => '🌸 Empress Korea'], 'stylemz.com' => ['name' => '👗 StyleMZ'], 'skinseoulshop.com' => ['name' => '🧴 Skin Seoul Shop'], ]; if (!isset($site_map[$host])) return; $site_name = $site_map[$host]['name']; // ✅ 주문 정보 $customer_name = trim($order->get_billing_first_name() . ' ' . $order->get_billing_last_name()); $order_date = $order->get_date_created() ? $order->get_date_created()->date('Y-m-d') : date('Y-m-d'); $country = $order->get_shipping_country() ?: 'N/A'; $shipping_usd = floatval($order->get_shipping_total()); $shipping_usd_formatted = number_format($shipping_usd, 2); $shipping_krw = number_format(round($shipping_usd * 1350)); // 환율 적용 // ✅ 아이템 정보 $items = []; foreach ($order->get_items() as $item) { $items[] = '• ' . $item->get_name() . ' x' . $item->get_quantity() . ' = $' . number_format($item->get_total(), 2); } // ✅ 메시지 $message = "📦 {$site_name} Fulfilled 🧾 Order ID: {$order_id} 👤 Customer: {$customer_name} 📅 Date: {$order_date} 🌍 Country: {$country} 🚚 Shipping: {$shipping_usd_formatted} USD (실제 지불: {$shipping_krw}원) 🛒 Items: " . implode("\n", $items); // ✅ 텔레그램 전송 $TELEGRAM_BOT_TOKEN = '7284506085:AAF2KUcnCiEWwU746OFiqOaZr2V60bQE9S8'; $TELEGRAM_CHAT_ID = '-1001776338940'; $telegram_url = "https://api.telegram.org/bot{$TELEGRAM_BOT_TOKEN}/sendMessage"; $response = wp_remote_post($telegram_url, [ 'headers' => ['Content-Type' => 'application/json; charset=utf-8'], 'body' => json_encode([ 'chat_id' => $TELEGRAM_CHAT_ID, 'text' => $message, // parse_mode 제거 → 일반 텍스트 ]), 'method' => 'POST', 'timeout' => 10, ]); if (is_wp_error($response)) { error_log('[Telegram Fulfilled] 전송 실패: ' . $response->get_error_message()); } }