// Hook alternativo - captura directamente el submit de Elementor add_action('elementor_pro/forms/new_record', function($record, $handler) { // Obtener todos los campos del formulario $raw_fields = $record->get('fields'); $client_email = ''; $items_json = ''; // Buscar los campos que necesitamos foreach ($raw_fields as $id => $field) { if ($id === 'client_email' || (isset($field['id']) && $field['id'] === 'client_email')) { $client_email = isset($field['value']) ? $field['value'] : $field; } if ($id === 'items_json' || (isset($field['id']) && $field['id'] === 'items_json')) { $items_json = isset($field['value']) ? $field['value'] : $field; } } // Log de debugging error_log('TecnoShades Hook - Email encontrado: ' . ($client_email ? 'SI' : 'NO')); error_log('TecnoShades Hook - Items encontrado: ' . ($items_json ? 'SI' : 'NO')); // Si no encontramos los campos, salir if (!$client_email || !$items_json) { error_log('TecnoShades Hook - Campos no encontrados. Dump: ' . print_r($raw_fields, true)); return; } // Validar email $client_email = sanitize_email($client_email); if (!is_email($client_email)) { error_log('TecnoShades Hook - Email invalido: ' . $client_email); return; } // Validar JSON $items = json_decode($items_json, true); if (!is_array($items) || empty($items)) { error_log('TecnoShades Hook - Items JSON invalido: ' . $items_json); return; } // Validar estructura de items foreach ($items as $it) { if (empty($it['product_id']) || !isset($it['ancho']) || !isset($it['alto']) || !isset($it['mando'])) { error_log('TecnoShades Hook - Estructura de item invalida: ' . print_r($it, true)); return; } } // Generar token $token = bin2hex(random_bytes(20)); // Guardar en DB $data = array( 'client_email' => $client_email, 'items' => $items, 'created_at' => current_time('mysql'), ); set_transient('ts_quote_' . $token, $data, 7 * DAY_IN_SECONDS); // Generar link $link = add_query_arg('ts_quote', $token, wc_get_cart_url()); // Enviar email usando la función que ya existe ts_send_quote_email($client_email, $link, $items); // Log de éxito error_log('TecnoShades Hook: Cotizacion ' . $token . ' creada para ' . $client_email . ' via hook de Elementor'); }, 10, 2); ```