Api ile çalışacak ücretsiz Woocommerce Aras kargo entegrasyonu aramaktayım fakat bulamadım bilgisi olan var mı?
Chatgpt'ye aras kargo entegrasyon kodu yazdırttım ne kadar doğru ne kadar yanlış bilmiyorum yardımcı olursanız sevinirim. function.php dosyasına yazmamı belirtti
// WooCommerce sipariş tamamlandığında çalışacak fonksiyon
function aras_kargo_entegrasyonu($order_id) {
// Aras Kargo API erişim bilgileri
$api_url = 'https://www.araskargo.com.tr/shipment-tracking/';
$api_key = 'ARAS_API_KEY'; // Aras Kargo tarafından sağlanan API anahtarını buraya yerleştirin
// WooCommerce sipariş nesnesini al
$order = wc_get_order($order_id);
// Sadece tamamlanmış siparişler için devam et
if (!$order->is_completed()) {
return;
}
// Müşteri bilgilerini al
$customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$customer_address = $order->get_billing_address_1() . ' ' . $order->get_billing_address_2();
$customer_city = $order->get_billing_city();
$customer_country = $order->get_billing_country();
$customer_phone = $order->get_billing_phone();
$customer_email = $order->get_billing_email();
// API için gereken verileri oluştur
$data = array(
'name' => $customer_name,
'address' => $customer_address,
'city' => $customer_city,
'country' => $customer_country,
'phone' => $customer_phone,
'email' => $customer_email
);
// Aras Kargo API'sine POST isteği gönder
$response = wp_remote_post($api_url, array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api_key
),
'body' => json_encode($data)
));
// API yanıtını kontrol et
if (is_wp_error($response)) {
// Hata durumunda işlemleri burada yönetebilirsiniz
error_log('Aras Kargo API hatası: ' . $response->get_error_message());
return;
}
// Yanıtı işle
$response_body = json_decode($response['body'], true);
if ($response_body && isset($response_body['tracking_number'])) {
$tracking_number = $response_body['tracking_number'];
// Kargo numarasını siparişe kaydet
$order->update_meta_data('Aras Kargo Takip Numarası', $tracking_number);
$order->save();
// Müşteriye kargo takip bilgilerini içeren e-posta gönder
$to = $customer_email;
$subject = 'Kargo Takip Bilgileri - Sipariş #' . $order_id;
$message = 'Siparişiniz kargoya verildi. Kargo takip numaran
Hele ki trafiği ve işlem hacmi yoğun bir siteyse.