├── .gitignore ├── index.php ├── .DS_Store ├── assets ├── logos │ ├── aras.png │ ├── dhl.png │ ├── filo.png │ ├── iyi.png │ ├── mng.png │ ├── ptt.png │ ├── tex.png │ ├── tnt.png │ ├── ups.png │ ├── fedex.png │ ├── horoz.png │ ├── sendeo.png │ ├── surat.png │ ├── carrtell.png │ ├── hepsijet.png │ ├── postman.png │ └── yurtici.png └── js │ └── kargo-checkout.js ├── .github └── workflows │ └── main.yml ├── mail-template ├── email-shipment-template.php └── email-shipment-update-template.php ├── kobikom-helper.php ├── config.php ├── kargo-takip-dashboard.php ├── readme.txt ├── kargo-takip-wc-api-helper.php ├── kargo-takip-helper.php ├── kargo-takip-order-list.php ├── kargo-takip-bulk-import.php ├── kargo-takip-checkout-fields.php ├── netgsm-helper.php ├── CLAUDE.md ├── kargo-takip-whatsapp-settings.php ├── kargo-takip-cargo-settings.php └── kargo-takip-cities-districts.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 25 | 26 | 27 | 28 | 29 |
get_billing_first_name())); ?>
30 |Siparişiniz kargoya verilmiştir. Takip bilgileri aşağıda yer almaktadır: 31 |
32 |
Kargo Firması Adı:
35 |Kargo Takip No:
36 | '; 39 | 40 | ?> 41 | 42 | Kargonuzu izlemek için buraya tıklayın. 43 | 44 |get_billing_first_name()));?>
30 |Siparişiniz kargoya verilmiştir. Takip bilgileri aşağıda yer almaktadır:
31 |
Kargo Firması Adı:
34 |Kargo Takip No:
35 | '; 38 | 39 | ?> 40 | 41 | Kargonuzu izlemek için buraya tıklayın. 42 | 43 |Günlük kargo gönderimlerinizi toplu olarak sisteme yükleyebilirsiniz. Dosya formatı aşağıdaki gibi olmalıdır:
16 | 17 |CSV dosyasında kullanabileceğiniz kargo firması isimleri (büyük/küçük harf duyarlı değildir):
65 |66 | 71 |
72 |Dosya yüklenirken bir hata oluştu.
'; 80 | return; 81 | } 82 | 83 | $file = $_FILES['csv_file']['tmp_name']; 84 | $handle = fopen($file, "r"); 85 | 86 | if ($handle === FALSE) { 87 | echo 'Dosya açılamadı.
İşlem Tamamlandı. Başarılı: ' . $success_count . '
Bazı satırlar işlenemedi (' . $error_count . ' hata):
'; 199 | echo ''.__('TC Kimlik No').': ' . esc_html($tc) . '
'; 184 | } 185 | 186 | if ($tax_enabled === 'yes') { 187 | $tax_office = $order->get_meta('_billing_tax_office'); 188 | $tax_number = $order->get_meta('_billing_tax_number'); 189 | if($tax_office) echo ''.__('Vergi Dairesi').': ' . esc_html($tax_office) . '
'; 190 | if($tax_number) echo ''.__('Vergi Numarası').': ' . esc_html($tax_number) . '
'; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /netgsm-helper.php: -------------------------------------------------------------------------------- 1 | array( 9 | 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password) 10 | ), 11 | 'timeout' => 15 12 | )); 13 | 14 | if (is_wp_error($request)) { 15 | return false; 16 | } 17 | 18 | $response = trim($request['body']); 19 | 20 | // Try to decode JSON response 21 | $data = json_decode($response, true); 22 | 23 | // Check if response is successful 24 | if (!$data || !isset($data['code']) || $data['code'] !== '00') { 25 | return false; 26 | } 27 | 28 | // Return msgheaders array 29 | if (isset($data['msgheaders']) && is_array($data['msgheaders'])) { 30 | return $data['msgheaders']; 31 | } 32 | 33 | return false; 34 | } 35 | 36 | function kargoTR_get_netgsm_packet_info($username, $password, $appkey = '') { 37 | // NetGSM Balance API - Returns JSON response 38 | $url = "https://api.netgsm.com.tr/balance"; 39 | 40 | // Build request body - appkey only if provided 41 | $request_body = array( 42 | 'usercode' => $username, 43 | 'password' => $password, 44 | 'stip' => 1 // 1 = All balance types 45 | ); 46 | 47 | // Add appkey only if it's not empty 48 | if (!empty($appkey)) { 49 | $request_body['appkey'] = $appkey; 50 | } 51 | 52 | $body = json_encode($request_body); 53 | 54 | $request = wp_remote_post($url, array( 55 | 'headers' => array('Content-Type' => 'application/json'), 56 | 'body' => $body, 57 | 'timeout' => 15 58 | )); 59 | 60 | if (is_wp_error($request)) { 61 | return array('error' => $request->get_error_message()); 62 | } 63 | 64 | $response_code = wp_remote_retrieve_response_code($request); 65 | if ($response_code !== 200) { 66 | return array('error' => 'HTTP Hata: ' . $response_code); 67 | } 68 | 69 | $response = trim(wp_remote_retrieve_body($request)); 70 | 71 | // Check if response is empty 72 | if (empty($response)) { 73 | return array('error' => 'Boş yanıt alındı'); 74 | } 75 | 76 | // Try to decode JSON response 77 | $data = json_decode($response, true); 78 | 79 | // Check for JSON decode errors 80 | if (json_last_error() !== JSON_ERROR_NONE) { 81 | return array('error' => 'JSON parse hatası: ' . json_last_error_msg() . ' | Yanıt: ' . substr($response, 0, 100)); 82 | } 83 | 84 | // Check for NetGSM API error codes 85 | if (isset($data['code'])) { 86 | $error_codes = array( 87 | '30' => 'Geçersiz kullanıcı adı veya şifre', 88 | '40' => 'Yetkilendirme hatası', 89 | '50' => 'Hesap erişim hatası', 90 | '51' => 'Erişim izni yok', 91 | '60' => 'AppKey hatası: AppKey yanlış, geçersiz veya bu kullanıcı için tanımlı değil. NetGSM panelinden AppKey\'inizi kontrol edin.', 92 | '70' => 'Hatalı sorgulama parametreleri', 93 | '85' => 'Başlık kullanım izni yok' 94 | ); 95 | 96 | $code = (string)$data['code']; 97 | if (isset($error_codes[$code])) { 98 | return array('error' => $error_codes[$code] . ' (Kod: ' . $code . ')'); 99 | } else { 100 | return array('error' => 'NetGSM API Hatası (Kod: ' . $code . ')'); 101 | } 102 | } 103 | 104 | // Check for API error messages 105 | if (isset($data['error'])) { 106 | return array('error' => $data['error']); 107 | } 108 | 109 | if (isset($data['message'])) { 110 | return array('error' => $data['message']); 111 | } 112 | 113 | // Check if balance array exists 114 | if (!isset($data['balance']) || !is_array($data['balance'])) { 115 | // If appkey was used, try without it 116 | if (!empty($appkey)) { 117 | // Retry without appkey 118 | $request_body_retry = array( 119 | 'usercode' => $username, 120 | 'password' => $password, 121 | 'stip' => 1 122 | ); 123 | 124 | $body_retry = json_encode($request_body_retry); 125 | $request_retry = wp_remote_post($url, array( 126 | 'headers' => array('Content-Type' => 'application/json'), 127 | 'body' => $body_retry, 128 | 'timeout' => 15 129 | )); 130 | 131 | if (!is_wp_error($request_retry)) { 132 | $response_retry = trim(wp_remote_retrieve_body($request_retry)); 133 | $data_retry = json_decode($response_retry, true); 134 | 135 | if (isset($data_retry['balance']) && is_array($data_retry['balance'])) { 136 | // Success without appkey 137 | foreach ($data_retry['balance'] as $item) { 138 | if (isset($item['balance_name']) && strpos($item['balance_name'], 'SMS') !== false) { 139 | return $item['amount'] . ' Adet SMS'; 140 | } 141 | } 142 | } 143 | } 144 | } 145 | 146 | return array('error' => 'Paket bilgisi bulunamadı. Yanıt: ' . substr($response, 0, 200)); 147 | } 148 | 149 | // Find SMS balance from the array 150 | foreach ($data['balance'] as $item) { 151 | if (isset($item['balance_name']) && strpos($item['balance_name'], 'SMS') !== false) { 152 | return $item['amount'] . ' Adet SMS'; 153 | } 154 | } 155 | 156 | // Return all balances as formatted string 157 | $balances = array(); 158 | foreach ($data['balance'] as $item) { 159 | if (isset($item['amount']) && isset($item['balance_name'])) { 160 | $balances[] = $item['amount'] . ' ' . $item['balance_name']; 161 | } 162 | } 163 | 164 | if (empty($balances)) { 165 | return array('error' => 'Paket bilgisi bulunamadı'); 166 | } 167 | 168 | return implode(', ', $balances); 169 | } 170 | 171 | function kargoTR_get_netgsm_credit_info($username, $password, $appkey = '') { 172 | // NetGSM Balance API - Returns JSON response 173 | $url = "https://api.netgsm.com.tr/balance"; 174 | 175 | // Build request body - appkey only if provided 176 | $request_body = array( 177 | 'usercode' => $username, 178 | 'password' => $password, 179 | 'stip' => 1 180 | ); 181 | 182 | // Add appkey only if it's not empty 183 | if (!empty($appkey)) { 184 | $request_body['appkey'] = $appkey; 185 | } 186 | 187 | $body = json_encode($request_body); 188 | 189 | $request = wp_remote_post($url, array( 190 | 'headers' => array('Content-Type' => 'application/json'), 191 | 'body' => $body, 192 | 'timeout' => 15 193 | )); 194 | 195 | if (is_wp_error($request)) { 196 | return false; 197 | } 198 | 199 | $response_code = wp_remote_retrieve_response_code($request); 200 | if ($response_code !== 200) { 201 | return false; 202 | } 203 | 204 | $response = trim(wp_remote_retrieve_body($request)); 205 | 206 | // Try to decode JSON response 207 | $data = json_decode($response, true); 208 | 209 | if (json_last_error() !== JSON_ERROR_NONE) { 210 | return false; 211 | } 212 | 213 | // Check for NetGSM API error codes 214 | if (isset($data['code'])) { 215 | // If appkey was used and got code 60, try without appkey 216 | if ($data['code'] == 60 && !empty($appkey)) { 217 | $request_body_retry = array( 218 | 'usercode' => $username, 219 | 'password' => $password, 220 | 'stip' => 1 221 | ); 222 | 223 | $body_retry = json_encode($request_body_retry); 224 | $request_retry = wp_remote_post($url, array( 225 | 'headers' => array('Content-Type' => 'application/json'), 226 | 'body' => $body_retry, 227 | 'timeout' => 15 228 | )); 229 | 230 | if (!is_wp_error($request_retry)) { 231 | $response_retry = trim(wp_remote_retrieve_body($request_retry)); 232 | $data_retry = json_decode($response_retry, true); 233 | 234 | if (isset($data_retry['balance']) && is_array($data_retry['balance'])) { 235 | foreach ($data_retry['balance'] as $item) { 236 | if (isset($item['balance_name']) && (strpos($item['balance_name'], 'TL') !== false || strpos($item['balance_name'], 'Kredi') !== false)) { 237 | return $item['amount']; 238 | } 239 | } 240 | } 241 | } 242 | } 243 | return false; 244 | } 245 | 246 | // Check for API error messages 247 | if (isset($data['error']) || isset($data['message'])) { 248 | return false; 249 | } 250 | 251 | if (!isset($data['balance']) || !is_array($data['balance'])) { 252 | return false; 253 | } 254 | 255 | // Find credit balance (TL) 256 | foreach ($data['balance'] as $item) { 257 | if (isset($item['balance_name']) && (strpos($item['balance_name'], 'TL') !== false || strpos($item['balance_name'], 'Kredi') !== false)) { 258 | return $item['amount']; 259 | } 260 | } 261 | 262 | return false; 263 | } 264 | 265 | 266 | function kargoTR_SMS_gonder_netgsm($order_id) { 267 | $order = wc_get_order($order_id); 268 | if (!$order) return; 269 | 270 | $phone = $order->get_billing_phone(); 271 | 272 | $NetGsm_UserName = get_option('NetGsm_UserName'); 273 | $NetGsm_Password = urlencode(get_option('NetGsm_Password')); 274 | $NetGsm_Header = get_option('NetGsm_Header'); 275 | $NetGsm_sms_url_send = get_option('NetGsm_sms_url_send'); 276 | 277 | // HPOS uyumlu meta okuma 278 | $tracking_company = $order->get_meta('tracking_company', true); 279 | $tracking_code = $order->get_meta('tracking_code', true); 280 | 281 | // Use the configurable SMS template 282 | $message = kargoTR_get_sms_template($order_id, get_option('kargoTR_sms_template')); 283 | $message = urlencode($message); 284 | 285 | /* Legacy logic - removed in favor of template 286 | $message = "Siparişinizin kargo takip numarası : " . $tracking_code . ", " . kargoTR_get_company_name($tracking_company) . " kargo firması ile takip edebilirsiniz."; 287 | $message = urlencode($message); 288 | 289 | if ($NetGsm_sms_url_send == 'yes') { 290 | $message = $message." ".urlencode("Takip URL : ").kargoTR_getCargoTrack($tracking_company, $tracking_code); 291 | } 292 | */ 293 | 294 | if($NetGsm_Header == "yes"){ 295 | $NetGsm_Header = kargoTR_get_netgsm_headers($NetGsm_UserName, $NetGsm_Password); 296 | $NetGsm_Header = $NetGsm_Header[0]; 297 | } 298 | 299 | $NetGsm_Header = urlencode($NetGsm_Header); 300 | 301 | $url= "https://api.netgsm.com.tr/sms/send/get/?usercode=$NetGsm_UserName&password=$NetGsm_Password&gsmno=$phone&message=$message&dil=TR&msgheader=$NetGsm_Header"; 302 | 303 | $request = wp_remote_get($url); 304 | 305 | // NetGSM API returns numeric error codes: 20, 30, 40, 50, 51, 70, 85 306 | // Success returns a job ID (can be "00 JOBID" format or just "JOBID") 307 | $response = trim($request['body']); 308 | $error_codes = array('20', '30', '40', '50', '51', '70', '85'); 309 | 310 | if (in_array($response, $error_codes)) { 311 | // Error occurred 312 | $error_messages = array( 313 | '20' => 'Mesaj metninde ki problemden dolayı gönderilemediğini veya standart maksimum mesaj karakter sayısını geçtiğini ifade eder.', 314 | '30' => 'Geçersiz kullanıcı adı, şifre veya kullanıcınızın API erişim izninin olmadığını gösterir.', 315 | '40' => 'Mesaj başlığınızın (gönderici adınızın) sistemde tanımlı olmadığını ifade eder.', 316 | '50' => 'Abone hesabınız ile İYS kontrollü gönderimler yapılamamaktadır.', 317 | '51' => 'Erişim izninizin olmadığı bir hesaba işlem yapmaya çalıştığınızı ifade eder.', 318 | '70' => 'Hatalı sorgulama. Gönderdiğiniz parametrelerden birisi hatalı veya zorunlu alanlardan birinin eksik olduğunu ifade eder.', 319 | '85' => 'Başlık kullanım izni olmayan bir API kullanıcısı ile başlıklı mesaj gönderilmeye çalışıldığını ifade eder.' 320 | ); 321 | $error_msg = isset($error_messages[$response]) ? $error_messages[$response] : 'Bilinmeyen hata'; 322 | $order->add_order_note("SMS Gönderilemedi - NetGSM Hata Kodu: {$response} - {$error_msg}"); 323 | } else { 324 | // Success - response is job ID (can be "00 JOBID" or just "JOBID") 325 | $parts = explode(" ", $response); 326 | $job_id = isset($parts[1]) ? $parts[1] : $response; 327 | $order->add_order_note("SMS Gönderildi - NetGSM İşlem Kodu: {$job_id}"); 328 | } 329 | 330 | // $order->add_order_note("Debug : ".$request['body']); 331 | 332 | } 333 | add_action('order_send_sms', 'kargoTR_SMS_gonder_netgsm'); 334 | 335 | ?> -------------------------------------------------------------------------------- /CLAUDE.md: -------------------------------------------------------------------------------- 1 | # Kargo Takip Türkiye WordPress Plugin 2 | 3 | ## Plugin Overview 4 | 5 | **Kargo Takip Türkiye** is a WooCommerce integration plugin for Turkish cargo/shipment tracking. It allows shop owners to manage shipment tracking information directly within WooCommerce order details and enables automated customer notifications via email and SMS. 6 | 7 | ### Key Information 8 | - **Plugin Name**: Kargo Takip Türkiye (Cargo Tracking Turkey) 9 | - **Current Version**: 0.2.0 10 | - **Author**: Unbelievable.Digital 11 | - **Repository**: https://github.com/unbelievable-digital/kargo-takip-turkiye 12 | - **Language**: Turkish (UI and documentation) 13 | - **WordPress Requirement**: 4.9+ 14 | - **PHP Requirement**: 7.1+ 15 | - **WooCommerce Tested**: 7.2.2+ 16 | - **License**: GPLv2 or later 17 | 18 | --- 19 | 20 | ## Directory Structure 21 | 22 | ``` 23 | kargo-takip-turkiye/ 24 | ├── .github/ 25 | │ └── workflows/ 26 | │ └── main.yml # GitHub Actions deployment workflow 27 | ├── assets/ 28 | │ └── logos/ # Cargo company logos (PNG images) 29 | │ ├── aras.png 30 | │ ├── carrtell.png 31 | │ ├── dhl.png 32 | │ ├── fedex.png 33 | │ ├── filo.png 34 | │ ├── hepsijet.png 35 | │ ├── horoz.png 36 | │ ├── iyi.png 37 | │ ├── mng.png 38 | │ ├── postman.png 39 | │ ├── ptt.png 40 | │ ├── sendeo.png 41 | │ ├── surat.png 42 | │ ├── tex.png 43 | │ ├── tnt.png 44 | │ ├── ups.png 45 | │ └── yurtici.png 46 | ├── mail-template/ # Email template files 47 | │ ├── email-shipment-template.php # Initial shipment notification 48 | │ └── email-shipment-update-template.php # Shipment update notification 49 | ├── .gitignore 50 | ├── config.php # Cargo company configuration 51 | ├── index.php # Empty entry point 52 | ├── kargo-takip-turkiye.php # Main plugin file 53 | ├── kargo-takip-helper.php # Helper functions 54 | ├── kargo-takip-order-list.php # Admin order list enhancements 55 | ├── kargo-takip-email-settings.php # Email settings page 56 | ├── kargo-takip-sms-settings.php # SMS settings page 57 | ├── kargo-takip-wc-api-helper.php # WooCommerce REST API endpoint 58 | ├── kobikom-helper.php # Kobikom SMS provider integration 59 | ├── netgsm-helper.php # NetGSM SMS provider integration 60 | ├── readme.txt # WordPress plugin readme 61 | └── LICENSE # GPLv2 License 62 | 63 | ``` 64 | 65 | --- 66 | 67 | ## Plugin Architecture & Components 68 | 69 | ### 1. Main Plugin Entry Point 70 | **File**: `kargo-takip-turkiye.php` 71 | 72 | The main plugin file that: 73 | - Includes all helper and settings files 74 | - Registers the admin menu and submenus 75 | - Manages WooCommerce hooks and filters 76 | - Registers custom order status "Kargoya verildi" (Shipped via Cargo) 77 | - Handles shipment tracking metadata on orders 78 | - Triggers email and SMS notifications 79 | - Adds shipment details to customer account pages and order confirmations 80 | 81 | **Key Functions**: 82 | - `kargoTR_register_admin_menu()` - Registers admin menu structure 83 | - `kargoTR_register_settings()` - Registers plugin option settings 84 | - `kargoTR_setting_page()` - Displays general settings page 85 | - `kargoTR_register_shipment_shipped_order_status()` - Adds custom order status 86 | - `kargoTR_general_shipment_details_for_admin()` - Admin order tracking form 87 | - `kargoTR_tracking_save_general_details()` - Saves tracking data, triggers notifications 88 | - `kargoTR_shipment_details()` - Displays tracking info on customer order page 89 | - `kargoTR_add_kargo_button_in_order()` - Adds tracking button to order actions 90 | - `kargoTR_kargo_bildirim_icerik()` - Renders email notification content 91 | - `kargoTR_kargo_eposta_details()` - Sends email notification 92 | 93 | ### 2. Configuration 94 | **File**: `config.php` 95 | 96 | PHP array containing all supported cargo companies with: 97 | - Company display name 98 | - Tracking URL pattern (base URL + tracking code) 99 | - Logo file path 100 | 101 | **Supported Cargo Companies** (20 companies): 102 | - PTT Kargo 103 | - Yurtiçi Kargo 104 | - Aras Kargo 105 | - MNG Kargo 106 | - Horoz Kargo 107 | - UPS Kargo 108 | - Sürat Kargo 109 | - Filo Kargo 110 | - TNT Kargo 111 | - DHL Kargo 112 | - FedEx Kargo 113 | - FoodMan Kargo 114 | - Postman Kargo 115 | - İyi Kargo 116 | - Trendyol Express 117 | - HepsiJET 118 | - Sendeo Kargo 119 | - Carrtell Kargo 120 | 121 | ### 3. Helper Functions 122 | **File**: `kargo-takip-helper.php` 123 | 124 | Core utility functions for cargo data retrieval: 125 | - `kargoTR_get_company_name()` - Get company name by key 126 | - `kargoTR_getCargoTrack()` - Build tracking URL 127 | - `kargoTR_getCargoName()` - Get cargo name (legacy) 128 | - `kargoTR_cargo_company_list()` - Get all companies as associative array 129 | - `kargoTR_get_order_cargo_logo()` - Get company logo for order 130 | - `kargoTR_get_order_cargo_information()` - Get complete cargo info (logo, company, URL) 131 | - `kargoTR_get_sms_template()` - Build SMS message from template with variables 132 | 133 | **Template Variables**: 134 | - `{customer_name}` - Customer name 135 | - `{order_id}` - Order ID 136 | - `{company_name}` - Cargo company name 137 | - `{tracking_number}` - Tracking code 138 | - `{tracking_url}` - Tracking URL 139 | 140 | ### 4. Settings Management 141 | 142 | #### General Settings 143 | **File**: `kargo-takip-turkiye.php` (main file) 144 | 145 | Registered options: 146 | - `kargo_hazirlaniyor_text` - Show "Preparing shipment" text 147 | - `mail_send_general` - Auto-send email on tracking info 148 | - `sms_provider` - Selected SMS provider (no, NetGSM, Kobikom) 149 | - `sms_send_general` - Auto-send SMS on tracking info 150 | 151 | #### Email Settings 152 | **File**: `kargo-takip-email-settings.php` 153 | 154 | - Manages email template customization via `kargoTr_email_template` option 155 | - Users can customize email content with template variables 156 | - Default template included in main plugin file 157 | 158 | #### SMS Settings 159 | **File**: `kargo-takip-sms-settings.php` 160 | 161 | Settings page for SMS integration: 162 | - Select SMS provider (NetGSM or Kobikom) 163 | - Configure provider credentials and API keys 164 | - View account balance and remaining credits 165 | - Customize SMS template with template variables 166 | 167 | ### 5. SMS Integration 168 | 169 | #### NetGSM Provider 170 | **File**: `netgsm-helper.php` 171 | 172 | Functions: 173 | - `kargoTR_get_netgsm_headers()` - Fetch available SMS headers 174 | - `kargoTR_get_netgsm_packet_info()` - Get packet information 175 | - `kargoTR_get_netgsm_credit_info()` - Get account credit balance 176 | - `kargoTR_SMS_gonder_netgsm()` - Send SMS via NetGSM API 177 | 178 | **Credentials**: 179 | - Subscriber code (without leading 0) 180 | - Password 181 | 182 | #### Kobikom Provider 183 | **File**: `kobikom-helper.php` 184 | 185 | Functions: 186 | - `kargoTR_get_kobikom_headers()` - Fetch available SMS headers 187 | - `kargoTR_get_kobikom_balance()` - Get account packages/balance 188 | - `kargoTR_SMS_gonder_kobikom()` - Send SMS via Kobikom API 189 | 190 | **Credentials**: 191 | - API Token/Key 192 | 193 | ### 6. Admin Order List Enhancement 194 | **File**: `kargo-takip-order-list.php` 195 | 196 | Adds a "Kargo" column to the WooCommerce orders admin page: 197 | - Shows cargo company logo (clickable) 198 | - Links directly to cargo tracking page 199 | - Integrated with `kargoTR_get_order_cargo_information()` 200 | 201 | ### 7. WooCommerce REST API Integration 202 | **File**: `kargo-takip-wc-api-helper.php` 203 | 204 | Provides REST API endpoint for external systems to add/update tracking info: 205 | - **Endpoint**: `POST /wp-json/wc/v3/kargo_takip` 206 | - **Authentication**: Requires logged-in user with `edit_shop_orders` capability 207 | - **Parameters**: 208 | - `order_id` (required) - Order ID 209 | - `shipment_company` (required) - Cargo company key 210 | - `tracking_code` (required) - Tracking number 211 | 212 | **Functions**: 213 | - `kargoTR_api_add_tracking_code()` - Main API handler 214 | - `kargoTR_is_valid_shipment_company()` - Validates company 215 | - `kargoTR_is_valid_order_id()` - Validates order 216 | 217 | **Features**: 218 | - Adds/updates tracking metadata on orders 219 | - Triggers email notification if enabled 220 | - Triggers SMS notification if configured 221 | - Adds order notes for audit trail 222 | 223 | ### 8. Email Templates 224 | **Directory**: `mail-template/` 225 | 226 | #### email-shipment-template.php 227 | - Initial shipment notification template 228 | - Uses WooCommerce email hooks for consistent styling 229 | - Displays: company name, tracking code, tracking link 230 | - Includes order details via WooCommerce hooks 231 | 232 | #### email-shipment-update-template.php 233 | - Similar to shipment template (appears to be duplicate or for updates) 234 | 235 | Both templates use: 236 | - `kargoTR_get_company_name()` - Display company 237 | - `kargoTR_getCargoTrack()` - Generate tracking URL 238 | - WooCommerce email hooks for standard content 239 | 240 | --- 241 | 242 | ## WordPress Hooks & Actions 243 | 244 | ### Hooks Used by Plugin 245 | 246 | **Custom Actions (defined by plugin)**: 247 | - `order_ship_mail` - Triggers email notification 248 | - `order_send_sms` - Triggers NetGSM SMS notification 249 | - `order_send_sms_kobikom` - Triggers Kobikom SMS notification 250 | 251 | **WordPress Actions (hooked by plugin)**: 252 | - `admin_menu` - Register admin menu 253 | - `admin_init` - Register settings 254 | - `init` - Register custom order status 255 | - `admin_head` - Add CSS for tooltips 256 | - `woocommerce_admin_order_data_after_order_details` - Display tracking form 257 | - `woocommerce_process_shop_order_meta` - Save tracking data 258 | - `woocommerce_after_order_details` - Display tracking on customer page 259 | - `rest_api_init` - Register REST API endpoint 260 | 261 | **WooCommerce Filters**: 262 | - `wc_order_statuses` - Add custom order status 263 | - `woocommerce_my_account_my_orders_actions` - Add tracking button 264 | 265 | **WooCommerce Email Hooks** (in templates): 266 | - `woocommerce_email_header()` 267 | - `woocommerce_email_order_details()` 268 | - `woocommerce_email_order_meta()` 269 | - `woocommerce_email_customer_details()` 270 | - `woocommerce_email_footer()` 271 | 272 | --- 273 | 274 | ## Data Storage 275 | 276 | ### WordPress Post Meta 277 | Stored on WooCommerce orders (posts): 278 | - `tracking_company` - Cargo company key (from config) 279 | - `tracking_code` - Shipment tracking number 280 | 281 | ### WordPress Options 282 | Settings stored in wp_options table: 283 | - `kargo_hazirlaniyor_text` - (yes/no) 284 | - `mail_send_general` - (yes/no) 285 | - `sms_provider` - (no/NetGSM/Kobikom) 286 | - `sms_send_general` - (yes/no) 287 | - `NetGsm_UserName` - NetGSM subscriber code 288 | - `NetGsm_Password` - NetGSM password 289 | - `NetGsm_Header` - Selected NetGSM SMS header 290 | - `NetGsm_sms_url_send` - Include tracking URL in SMS 291 | - `Kobikom_ApiKey` - Kobikom API token 292 | - `Kobikom_Header` - Selected Kobikom SMS header 293 | - `kargoTr_sms_template` - SMS message template 294 | - `kargoTr_email_template` - Email message template 295 | 296 | ### Custom Order Status 297 | - **Status Key**: `wc-kargo-verildi` 298 | - **Display Label**: Kargoya Verildi (Shipped via Cargo) 299 | 300 | --- 301 | 302 | ## External API Integrations 303 | 304 | ### NetGSM API 305 | - **Base URL**: https://api.netgsm.com.tr/ 306 | - **Endpoints Used**: 307 | - `/sms/header/` - Get SMS headers 308 | - `/balance/list/get/` - Get account info 309 | - `/sms/send/get/` - Send SMS messages 310 | - **Authentication**: Usercode + Password 311 | 312 | ### Kobikom API 313 | - **Base URL**: https://sms.kobikom.com.tr/api/ 314 | - **Endpoints Used**: 315 | - `/subscription` - Get SMS headers 316 | - `/balance` - Get account packages 317 | - `/message/send` - Send SMS messages 318 | - **Authentication**: API Token 319 | 320 | --- 321 | 322 | ## Admin Pages Structure 323 | 324 | ### Menu 325 | ``` 326 | Kargo Takip (main menu) 327 | ├── Genel Ayarlar (General Settings) 328 | ├── E-Mail Ayarlari (Email Settings) 329 | └── SMS Ayarlari (SMS Settings) 330 | ``` 331 | 332 | ### General Settings Page 333 | - Show "Preparing shipment" text option 334 | - Auto-send email option 335 | - SMS provider selection 336 | 337 | ### Email Settings Page 338 | - Email template editor (textarea) 339 | - Template variable documentation 340 | - Examples of usage 341 | 342 | ### SMS Settings Page 343 | - SMS provider selection (NetGSM or Kobikom) 344 | - Provider-specific configuration 345 | - Account balance display 346 | - SMS template editor 347 | - Template variable documentation 348 | 349 | --- 350 | 351 | ## Admin Order Editing 352 | 353 | When editing a WooCommerce order: 354 | 1. Select2 dropdown for cargo company selection 355 | 2. Text input for tracking code 356 | 3. Automatic order status change to "Kargoya verildi" 357 | 4. Triggered notifications (email/SMS based on settings) 358 | 5. Automatic order note creation 359 | 360 | --- 361 | 362 | ## Development & Deployment 363 | 364 | ### GitHub Actions Workflow 365 | **File**: `.github/workflows/main.yml` 366 | 367 | Automated deployment process: 368 | - **Trigger**: Git tag creation 369 | - **Action**: 10up WordPress Plugin Deploy action 370 | - **Target**: WordPress.org SVN repository 371 | - **Slug**: kargo-takip-turkiye 372 | - **Authentication**: SVN_USERNAME and SVN_PASSWORD secrets 373 | 374 | ### Version Information 375 | Maintained in `kargo-takip-turkiye.php` header and `readme.txt` 376 | 377 | --- 378 | 379 | ## Code Quality & Standards 380 | 381 | ### Security Practices 382 | - Uses WordPress sanitization: `wc_clean()`, `wc_sanitize_textarea()` 383 | - Uses WordPress escaping: `esc_attr()`, `esc_html__()` 384 | - Capability checks: `current_user_can('edit_shop_orders')` 385 | - Input validation in REST API handler 386 | 387 | ### WordPress Standards 388 | - Uses WooCommerce plugin functions and classes 389 | - Follows WooCommerce template structure 390 | - Uses appropriate hooks and filters 391 | - Option registration and management 392 | 393 | ### Coding Patterns 394 | - Functional approach (no classes) 395 | - Include-based module loading 396 | - Configuration-driven cargo list 397 | - Action-based notification system 398 | 399 | --- 400 | 401 | ## Known Issues & Notes 402 | 403 | ### From Version History (readme.txt) 404 | 405 | **v0.2.0** (Latest) 406 | - SMS and Email templates now editable from admin panel 407 | - API added for external cargo data input via WooCommerce REST 408 | - Added Carrtell cargo company 409 | - Code structure improvements 410 | - Aras Kargo URL updated 411 | 412 | **Previous Improvements**: 413 | - Select2 for company dropdown 414 | - Kobikom SMS provider support 415 | - NetGSM SMS provider support 416 | - Email notification feature 417 | - Custom order status 418 | - Auto SMS/Email on tracking info 419 | - Multiple cargo companies support 420 | 421 | --- 422 | 423 | ## Dependencies 424 | 425 | ### Required 426 | - WordPress 4.9+ 427 | - WooCommerce 7.2.2+ 428 | - PHP 7.1+ 429 | 430 | ### WordPress Libraries Used 431 | - `wp_remote_get()` - HTTP requests 432 | - `wp_enqueue_script()` - Script loading 433 | - `wp_add_inline_script()` - Inline scripts 434 | - `wc_get_order()` - Order handling 435 | - `get_post_meta()` / `update_post_meta()` - Order metadata 436 | - `get_option()` / `update_option()` - Settings management 437 | - `register_post_status()` - Custom order status 438 | - `register_rest_route()` - REST API 439 | - `register_setting()` - Settings registration 440 | 441 | ### Frontend Libraries 442 | - Select2 (enqueued via WordPress) 443 | - jQuery (WooCommerce core) 444 | 445 | --- 446 | 447 | ## File Dependencies 448 | 449 | ``` 450 | kargo-takip-turkiye.php (main) 451 | ├── includes: netgsm-helper.php 452 | ├── includes: kargo-takip-helper.php 453 | ├── includes: kargo-takip-order-list.php 454 | ├── includes: kargo-takip-email-settings.php 455 | ├── includes: kargo-takip-sms-settings.php 456 | │ └── includes: kobikom-helper.php 457 | └── includes: kargo-takip-wc-api-helper.php 458 | └── uses: config.php 459 | ``` 460 | 461 | Helper files also include config.php independently to get cargo data. 462 | 463 | --- 464 | 465 | ## Extension Points 466 | 467 | ### Adding New Cargo Companies 468 | 1. Add entry to `config.php` in "cargoes" array 469 | 2. Add logo PNG to `assets/logos/` 470 | 3. Entry format: 471 | ```php 472 | "key" => array( 473 | "company" => "Company Name", 474 | "url" => "https://tracking.example.com/?code=", 475 | "logo" => "assets/logos/key.png" 476 | ) 477 | ``` 478 | 479 | ### Adding New SMS Providers 480 | 1. Create new helper file (e.g., `newprovider-helper.php`) 481 | 2. Implement functions: 482 | - `kargoTR_SMS_gonder_newprovider($order_id)` - Main sender 483 | - Additional API functions as needed 484 | 3. Add action: `add_action('order_send_sms_newprovider', ...)` 485 | 4. Update `kargo-takip-sms-settings.php` for UI 486 | 5. Update `kargo-takip-turkiye.php` to trigger action 487 | 488 | ### Customizing Email/SMS Templates 489 | - Use WordPress options to store templates 490 | - Use template variables in curly braces 491 | - Template rendering in `kargoTR_get_sms_template()` 492 | - Email template via `kargoTR_kargo_bildirim_icerik()` 493 | 494 | --- 495 | 496 | ## Testing Considerations 497 | 498 | ### Manual Testing Points 499 | 1. **Cargo Selection**: Test Select2 dropdown with multiple companies 500 | 2. **Tracking Data**: Verify metadata saved correctly 501 | 3. **Email Notification**: Check email sent with correct variables 502 | 4. **SMS Notifications**: Test both NetGSM and Kobikom providers 503 | 5. **API Endpoint**: Test POST request with valid/invalid data 504 | 6. **Order Status**: Verify "Kargoya verildi" status applied 505 | 7. **Admin Pages**: Test all three settings pages 506 | 8. **Customer View**: Verify tracking info displays on customer account 507 | 508 | ### API Testing 509 | ```bash 510 | POST /wp-json/wc/v3/kargo_takip 511 | Content-Type: application/x-www-form-urlencoded 512 | 513 | order_id=123&shipment_company=ptt&tracking_code=XXXXX 514 | ``` 515 | 516 | --- 517 | 518 | ## Recent Changes (v0.2.0) 519 | 520 | - **Email/SMS Templates**: Now editable from admin panel instead of hardcoded 521 | - **REST API**: Added WooCommerce REST API endpoint for external integration 522 | - **Carrtell Integration**: New cargo company added 523 | - **Code Refactoring**: Improved code organization and readability 524 | - **URL Updates**: Aras Kargo tracking URL changed 525 | 526 | --- 527 | 528 | ## License 529 | 530 | GPL v2 or later - See LICENSE file 531 | 532 | --- 533 | 534 | ## Support & Contribution 535 | 536 | **Repository**: https://github.com/unbelievable-digital/kargo-takip-turkiye 537 | **Author**: Unbelievable.Digital 538 | **WordPress.org Page**: https://wordpress.org/plugins/kargo-takip-turkiye/ 539 | 540 | --- 541 | 542 | **Last Updated**: November 2024 543 | **Document Version**: Based on Plugin v0.2.0 544 | 545 | ## Rules 546 | 547 | You are an expert in WordPress, PHP, and related web development technologies. 548 | 549 | Key Principles 550 | - Write concise, technical responses with accurate PHP examples. 551 | - Follow WordPress coding standards and best practices. 552 | - Use object-oriented programming when appropriate, focusing on modularity. 553 | - Prefer iteration and modularization over duplication. 554 | - Use descriptive function, variable, and file names. 555 | - Use lowercase with hyphens for directories (e.g., wp-content/themes/my-theme). 556 | - Favor hooks (actions and filters) for extending functionality. 557 | 558 | PHP/WordPress 559 | - Use PHP 7.4+ features when appropriate (e.g., typed properties, arrow functions). 560 | - Follow WordPress PHP Coding Standards. 561 | - Use strict typing when possible: declare(strict_types=1); 562 | - Utilize WordPress core functions and APIs when available. 563 | - File structure: Follow WordPress theme and plugin directory structures and naming conventions. 564 | - Implement proper error handling and logging: 565 | - Use WordPress debug logging features. 566 | - Create custom error handlers when necessary. 567 | - Use try-catch blocks for expected exceptions. 568 | - Use WordPress's built-in functions for data validation and sanitization. 569 | - Implement proper nonce verification for form submissions. 570 | - Utilize WordPress's database abstraction layer (wpdb) for database interactions. 571 | - Use prepare() statements for secure database queries. 572 | - Implement proper database schema changes using dbDelta() function. 573 | 574 | Dependencies 575 | - WordPress (latest stable version) 576 | - Composer for dependency management (when building advanced plugins or themes) 577 | 578 | WordPress Best Practices 579 | - Use WordPress hooks (actions and filters) instead of modifying core files. 580 | - Implement proper theme functions using functions.php. 581 | - Use WordPress's built-in user roles and capabilities system. 582 | - Utilize WordPress's transients API for caching. 583 | - Implement background processing for long-running tasks using wp_cron(). 584 | - Use WordPress's built-in testing tools (WP_UnitTestCase) for unit tests. 585 | - Implement proper internationalization and localization using WordPress i18n functions. 586 | - Implement proper security measures (nonces, data escaping, input sanitization). 587 | - Use wp_enqueue_script() and wp_enqueue_style() for proper asset management. 588 | - Implement custom post types and taxonomies when appropriate. 589 | - Use WordPress's built-in options API for storing configuration data. 590 | - Implement proper pagination using functions like paginate_links(). 591 | 592 | Key Conventions 593 | 1. Follow WordPress's plugin API for extending functionality. 594 | 2. Use WordPress's template hierarchy for theme development. 595 | 3. Implement proper data sanitization and validation using WordPress functions. 596 | 4. Use WordPress's template tags and conditional tags in themes. 597 | 5. Implement proper database queries using $wpdb or WP_Query. 598 | 6. Use WordPress's authentication and authorization functions. 599 | 7. Implement proper AJAX handling using admin-ajax.php or REST API. 600 | 8. Use WordPress's hook system for modular and extensible code. 601 | 9. Implement proper database operations using WordPress transactional functions. 602 | 10. Use WordPress's WP_Cron API for scheduling tasks. 603 | -------------------------------------------------------------------------------- /kargo-takip-whatsapp-settings.php: -------------------------------------------------------------------------------- 1 | 13 |Bu özellik Facebook WhatsApp Business API kullanılarak çalışmaktadır.
176 |Profesyonel kargo bildirimleri göndermek için onaylı bir şablon gereklidir.
177 | 178 | API Dokümantasyonu 179 | 180 |site_adi |
194 | Site adı | 195 |
order_id |
198 | Sipariş numarası | 199 |
shipment_name |
202 | Kargo firması | 203 |
shipment_number |
206 | Takip numarası | 207 |
Sistemde olmayan bir kargo firması ekleyin.
36 |Sistemde kayıtlı tüm kargo firmalarını görüntüleyin ve yönetin.
92 || Logo | 98 |Firma Adı | 99 |Anahtar | 100 |Takip URL | 101 |Teslimat (Gün) | 102 |Durum | 103 |
|---|---|---|---|---|---|
|
121 |
122 | |
127 | 128 | 129 | 130 | Özel 131 | 132 | Varsayılan 133 | 134 | | 135 | |
136 | 137 | 138 | ... 139 | 140 | | 141 |142 | 146 | 150 | | 151 |152 | 158 | | 159 |
{code} placeholder'ı kullanarak takip kodunun yerini belirleyebilirsiniz. Kullanmazsanız kod URL'in sonuna eklenir.
188 | Toggle ile firmaları aktif/pasif yapabilirsiniz.
201 |Pasif firmalar sipariş formlarındaki dropdown listesinde görünmez.
202 |