K
K
Khabib Omarov2020-02-01 16:57:28
Bitrix24
Khabib Omarov, 2020-02-01 16:57:28

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:

  1. Product names
  2. Shipping cost in number format
  3. Total amount of the order with delivery in number format

This data is required to be transferred to Bitrix24 via a webhook to create a lead.

Now the rest of the parameters are passed as follows:
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

1 answer(s)
W
WP Panda, 2020-02-01
@temp-market

I gave you a link to the class object in the previous answer, all the methods are documented there, is it really hard to read and paste?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question