Answer the question
In order to leave comments, you need to log in
How to pull data from WC Order on WooCommerce checkout?
It is necessary to pull out the following fields related to WC Order from the order during checkout:
add_action( 'woocommerce_new_order', 'wpp_create_invoice_for_wc_order', 10, 1 );
function wpp_create_invoice_for_wc_order( $order_id ) {
$order = new WC_Order( $order_id );
$queryUrl = 'https://pir555565.bitrix24.ru/rest/1/6p32hpfsxbvb4hja/crm.lead.add.json';
// формируем параметры для создания лида в переменной $queryData
$queryData = http_build_query(array(
'fields' => array(
'TITLE' => "Заказ с сайта № " . $order-> get_order_number(), // номер заказа
'NAME' => $order->get_billing_first_name(), // имя клиента
'LAST_NAME' => $order->get_billing_last_name(), // фамилия клиента
'PHONE' => array( // телефон
'n0' => array(
'VALUE' => $order->get_billing_phone(),
'VALUE_TYPE' => "WORK",
)),
'EMAIL' => array( // почта
'n0' => array(
'VALUE' => $order->get_billing_email(),
'VALUE_TYPE' => "WORK",
)),
'ADDRESS_COUNTRY' => "Россия",
'ADDRESS_CITY' => $order->get_billing_state(), //город
'ADDRESS' => $order->get_billing_address_1(), // адрес доставки
'SOURCE_ID' => "WEB", // источник лида
),
'params' => array("REGISTER_SONET_EVENT" => "Y")
));
// обращаемся к Битрикс24 при помощи функции curl_exec
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $queryUrl,
CURLOPT_POSTFIELDS => $queryData,
));
$result = curl_exec($curl);
curl_close($curl);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question