Привет, я разрабатываю плагин, который добавляет новое поле в заказ (WooCommerce). Поле должно сделать ajax-запрос к файлу в моем плагине, этот файл затем должен сделать запрос cURL на другой веб-сайт (или wp_remote_post). Но я испытываю трудности при оформлении запроса.Сделать wp_remote_post, когда не вошел в систему
Я не могу получить обычный cURL для работы или функцию wp_remote_post.
Вот фрагмент cURL в моем файле, который запрашивает ajax.
<?php
$shipping_place = array(
'country_code' => $country_code,
'postcode' => $postcode,
'street' => $street,
'number_of_droppoints' => $number_of_droppoints
);
$auth = array(
'Content-Type: application/json',
'Authorization: Basic '. base64_encode('user:password')
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $auth);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $shipping_place);
$result = curl_exec($ch);
if(curl_errno($ch)){
$msg = 'Curl error: ' . curl_error($ch);
} else {
$result = json_decode($result['body']);
if ($result->status == 'error') {
echo $result;
}
pred($result);
echo $result->result;
}
curl_close ($ch);
>
Любые дополнительные детали или фрагменты кода для обмена в вашем ответе? Помогло бы другим. – Alfabravo
Конечно, здесь есть ссылка: [link] (https://codex.wordpress.org/Function_Reference/wp_localize_script) – RasmusBS