Last active
July 19, 2021 15:09
-
-
Save mydropcrm/78effceaa655d24a001e490987c13ee0 to your computer and use it in GitHub Desktop.
Код для интеграции получения заказа из формы заказа в один клик сайта на WooCommerce (версия для поставщиков)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$product1 = wc_get_product( $product_id ); | |
$products = array(); | |
foreach($order->get_items() as $item) { | |
$product = $item->get_data(); | |
$product_meta = $product['meta_data'][0]; | |
$product_not_exist_vendor_not_exist = array( | |
'product_title' => $product1->get_name(), // название нового товара | |
'product_sku' => wc_get_product($product['product_id'])->get_sku(), | |
'price' => $product1->get_price(), // цена продажи товара | |
'amount' => $product['quantity'], // количество товара | |
'size_title' => mb_strtoupper($product_meta->value) // размер товара (необязательно) | |
); | |
array_push($products, $product_not_exist_vendor_not_exist); | |
} | |
// параметры запроса | |
$data = array( | |
'name' => $user_passed_text, // имя и фамилия покупателя | |
'phone' => $user_passed_tel, // телефон | |
'products' => $products, // массив с товарами заказа | |
'order_source' => 'Сайт', // источник заказа (необязательно) | |
'traffic_source' => 'AdWords', // источник трафика (необязательно) | |
'description' => 'Заказ в один клик' | |
); | |
// запрос | |
$curl = curl_init(); | |
$production_url = 'https://backend.mydrop.com.ua/vendor/api/orders'; | |
curl_setopt($curl, CURLOPT_URL, $production_url); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array( | |
'X-API-KEY: ваш_API_ключ', // замените на ваш API-ключ | |
'Content-Type: application/json' | |
)); | |
$out = curl_exec($curl); | |
curl_close($curl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment