// Reemplaza la función pakke_cotizador_ajax con esta versión mejorada
function pakke_cotizador_ajax() {
try {
// Verificar nonce para seguridad
check_ajax_referer('pakke_cotizador_nonce', 'security');
// Validar campos requeridos
$required_fields = ['zipcode_from', 'zipcode_to', 'weight', 'length', 'width', 'height'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field]) || empty($_POST[$field])) {
throw new Exception('Todos los campos son requeridos');
}
}
// Sanitizar inputs
$zipcode_from = substr(sanitize_text_field($_POST['zipcode_from']), 0, 5);
$zipcode_to = substr(sanitize_text_field($_POST['zipcode_to']), 0, 5);
$weight = max(0.1, floatval($_POST['weight']));
$length = max(1, floatval($_POST['length']));
$width = max(1, floatval($_POST['width']));
$height = max(1, floatval($_POST['height']));
// Verificar API Key
$api_key = get_option('pakke_api_key');
if (empty($api_key)) {
throw new Exception('API Key no configurada. Contacta al administrador.');
}
// Obtener cotización
$response = pakke_get_shipping_quote($zipcode_from, $zipcode_to, $weight, $length, $width, $height, $api_key);
if (is_wp_error($response)) {
throw new Exception($response->get_error_message());
}
if (empty($response['Pakke'])) {
throw new Exception('No hay servicios disponibles para esta ruta');
}
wp_send_json_success($response);
} catch (Exception $e) {
wp_send_json_error($e->getMessage());
}
}
Cargador Wireless Qi Spigen Essential F302W – iGadgets MX
Saltar al contenido
“Boton Home fisico Negro iPhone 4s” se ha añadido a tu carrito.
Ver carrito