|
|
@ -132,3 +132,51 @@ function ajax_edit_pet() { |
|
|
|
add_action('wp_ajax_edit_pet', 'ajax_edit_pet'); |
|
|
|
add_action('wp_ajax_edit_pet', 'ajax_edit_pet'); |
|
|
|
add_action('wp_ajax_nopriv_edit_pet', 'ajax_edit_pet'); |
|
|
|
add_action('wp_ajax_nopriv_edit_pet', 'ajax_edit_pet'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_action('wp_ajax_update_subscription_address', 'handle_subscription_address_update'); |
|
|
|
|
|
|
|
add_action('wp_ajax_nopriv_update_subscription_address', 'handle_subscription_address_update'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handle_subscription_address_update() { |
|
|
|
|
|
|
|
error_log('=== [AJAX] Запуск update_subscription_address ==='); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log('[AJAX] Nonce из формы: ' . ($_POST['address_nonce'] ?? 'none')); |
|
|
|
|
|
|
|
error_log('[AJAX] Проверка nonce: ' . (wp_verify_nonce($_POST['address_nonce'], 'update_subscription_address') ? 'OK' : 'FAIL')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($_POST['address_nonce']) || !wp_verify_nonce($_POST['address_nonce'], 'update_subscription_address')) { |
|
|
|
|
|
|
|
error_log('[AJAX] Ошибка nonce'); |
|
|
|
|
|
|
|
wp_send_json_error(['message' => pll__('Ошибка безопасности. Обновите страницу.')]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_user_logged_in()) { |
|
|
|
|
|
|
|
error_log('[AJAX] Пользователь не авторизован'); |
|
|
|
|
|
|
|
wp_send_json_error(['message' => pll__('Вы не авторизованы.')]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$subscription_id = intval($_POST['subscription_id'] ?? 0); |
|
|
|
|
|
|
|
$address_1 = sanitize_text_field($_POST['address'] ?? ''); |
|
|
|
|
|
|
|
$city = sanitize_text_field($_POST['city'] ?? ''); |
|
|
|
|
|
|
|
$comment = sanitize_textarea_field($_POST['comment'] ?? ''); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log("[AJAX] Получено: ID={$subscription_id}, Address={$address_1}, City={$city}, Comment={$comment}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$subscription_id || empty($address_1)) { |
|
|
|
|
|
|
|
wp_send_json_error(['message' => pll__('Недостаточно данных.')]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$subscription = wcs_get_subscription($subscription_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$subscription || $subscription->get_user_id() !== get_current_user_id()) { |
|
|
|
|
|
|
|
wp_send_json_error(['message' => pll__('Подписка не найдена или не принадлежит вам.')]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_post_meta($subscription_id, '_shipping_address_1', $address_1); |
|
|
|
|
|
|
|
update_post_meta($subscription_id, '_shipping_city', $city); |
|
|
|
|
|
|
|
update_post_meta($subscription_id, '_shipping_comment', $comment); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$subscription->set_customer_note($comment); |
|
|
|
|
|
|
|
$subscription->save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log('[AJAX] Подписка обновлена: ' . $subscription_id); |
|
|
|
|
|
|
|
wp_send_json_success(['message' => pll__('Адрес доставки успешно обновлён.')]); |
|
|
|
|
|
|
|
} |
|
|
|