** * Elementor → Clienty API REST * Auth: Basic Auth (Base64) * Landing + Tags automáticos */ add_action('elementor_pro/forms/new_record', function ($record) { // =============================== // 1. Obtener campos del formulario // =============================== $raw_fields = $record->get('fields'); $fields = []; foreach ($raw_fields as $id => $field) { $fields[$id] = $field['value']; } // =============================== // 2. Landing URL real // =============================== $landing_url = $_SERVER['HTTP_REFERER'] ?? home_url(); // =============================== // 3. Etiqueta automática por URL // =============================== $path = parse_url($landing_url, PHP_URL_PATH); $path = trim($path, '/'); $auto_tag = $path ? strtoupper(str_replace('-', ' ', $path)) : 'FORMULARIO WEB'; // =============================== // 4. Si existe hidden tag en Elementor // =============================== $final_tag = !empty($fields['tag']) ? $fields['tag'] : $auto_tag; // =============================== // 5. Payload según documentación Clienty // =============================== $data = [ "lead" => [ "name" => $fields['name'] ?? '', "lastName" => $fields['lastName'] ?? '', "email" => $fields['email'] ?? '', "phone" => $fields['phone'] ?? '', // 👉 SOLO el textarea "message" => $fields['message'] ?? '', // ✅ CANAL DE ADQUISICIÓN (POR NOMBRE) "acquisitionChannel" => [ "name" => "Formulario Web Spatio" ], "source" => "Formulario Elementor", "landed_url" => $landing_url, "tags" => [$final_tag], // 👉 AQUÍ ESTÁ LA MAGIA "customFields" => [ [ "name" => "Landing page", "value" => $landing_url ], [ "name" => "Producto de interés", "value" => $fields['producto_interes'] ?? '' ], [ "name" => "Tipo de Proyecto", "value" => $fields['tipo_proyecto'] ?? '' ], ] ] ]; // =============================== // 6. BASIC AUTH (AQUÍ SE CONVIERTE A BASE64) // =============================== $username = 'Venuska'; $password = 'f3kQMz8h'; // 👉 ESTA LÍNEA ES LA CLAVE $auth = base64_encode($username . ':' . $password); // =============================== // 7. Envío a Clienty // =============================== wp_remote_post( 'https://spatioterrazabioclimatica.clienty.co/api/integration/lead', [ 'method' => 'POST', 'timeout' => 20, 'headers' => [ 'Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json' ], 'body' => wp_json_encode($data) ] ); });