Всем привет Уже какой день пытаюсь выполнить интеграцию, но плохо получается Один раз отправил заказ в Frontpad, а потом всё, заглох Не понимаю в чём проблема PHP: <?php /* * Send order data to Frontpad * Отправка данных заказа во Frontpad */ require(dirname(__FILE__) . '/wp-load.php'); add_action('woocommerce_thankyou', 'send_order_to_frontpad'); function send_order_to_frontpad($order_id) { $order = wc_get_order($order_id); $api_password = '000'; $email = $order->billing_email; $phone = $order->billing_phone; $shipping_type = $order->get_shipping_method(); if ($order->get_payment_method_title() == 'Оплата при получении') { $shipping_type = ''; } else { $shipping_type = 947; } $shipping_cost = $order->get_total_shipping(); // get product details // получение данных товара $items = $order->get_items(); $item_name = array(); $item_qty = array(); $item_price = array(); $item_sku = array(); // set the address fields // установка полей адреса $user_id = $order->user_id; $address_fields = array( 'country', 'title', 'given_name', 'surname', 'street', 'house', 'pod', 'et', 'apart', ); $order_details = array(); foreach ($order->get_meta_data() as $item) { $order_details[$item->jsonSerialize()['key']] = $item->jsonSerialize()['value']; } $address = array(); if (is_array($address_fields)) { foreach ($address_fields as $field) { $address['billing_' . $field] = get_user_meta($user_id, 'billing_' . $field, true); $address['shipping_' . $field] = get_user_meta($user_id, 'shipping_' . $field, true); $address['billing_' . $field] = $order_details['_billing_' . $field]; $address['shipping_' . $field] = $order_details['_shipping_' . $field]; } } $address['pre_order'] = get_post_meta($order_id, 'pre_order', true); foreach ($items as $item_id => $item) { $item_name[] = $item['name']; $item_qty[] = $item['qty']; $item_price[] = $item['line_total']; $item_id = $item['product_id']; $product = new WC_Product($item['product_id']); $product_variation_id = $item['variation_id']; $product = $order->get_product_from_item($item); // Get SKU // Получение артикула $item_sku[] = $product->get_sku(); } // setup the data which has to be sent // сбор данных для отправки $data = array( 'secret' => $api_password, 'street' => $address['billing_street'], 'home' => $address['billing_house'], 'pod' => $address['billing_pod'], 'et' => $address['billing_et'], 'apart' => $address['billing_apart'], 'phone' => $phone, 'mail' => $email, 'descr' => $order->get_customer_note(), 'name' => $address['billing_given_name'] . ' ' . $address['billing_surname'], 'pay' => $shipping_type, 'datetime' => date('Y-m-d G:i:s', $order->get_date_created()->getOffsetTimestamp()), ); //get data from shipping address if is not empty // если указан адрес доставки, берем данные оттуда, если нет, то из платежного адреса if ($address['shipping_street'] != "") { $data['street'] = $address['shipping_street']; } if ($address['shipping_house'] != "") { $data['home'] = $address['shipping_house']; } if ($address['shipping_pod'] != "") { $data['pod'] = $address['shipping_pod']; } if ($address['shipping_et'] != "") { $data['et'] = $address['shipping_et']; } if ($address['shipping_apart'] != "") { $data['apart'] = $address['shipping_apart']; } if (($address['shipping_given_name'] != "") && ($address['shipping_surname'] != "")) { $data['name'] = $address['shipping_given_name'] . ' ' . $address['shipping_surname']; } if ($address['pre_order'] != '') { $data['datetime'] = date('Y-m-d G:i:s', strtotime($address['pre_order'])); } foreach ($order->get_items('shipping') as $item_id => $shipping_item_obj) { $data['descr'] = $data['descr'] . ' Доставка: ' . $shipping_item_obj->get_method_title(); } $query = ''; // request preparation // подготовка запроса foreach ($data as $key => $value) { $query .= "&" . $key . "=" . $value; } // order contents // содержимое заказа foreach ($item_sku as $key => $value) { $query .= "&product[" . $key . "]=" . $value . ""; $query .= "&product_kol[" . $key . "]=" . $item_qty[$key] . ""; } // send API request via cURL // отправка запроса API через cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://app.frontpad.ru/api/index.php?new_order"); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); $response = curl_exec($ch); curl_close($ch); $response = json_decode($response, true); if ($response['result'] == 'success') { update_post_meta($order_id, 'Frontpad Order ID', sanitize_text_field($response['order_id'])); update_post_meta($order_id, 'Frontpad Order Number', sanitize_text_field($response['order_number'])); // sending SMS to restaurant administrator // отправка запроса администратору ресторана $message = 'Новый онлайн-заказ №' . $response['order_number'] . '. Проверьте FrontPad. '; $message = urlencode($message); // $curl = curl_init(); // curl_setopt($curl, CURLOPT_URL, "https://sms.ru/sms/send?api_id=A9E14A13-D771-2D94-0E03-827654F39624&to=79923050626&msg=$message&json=1"); // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // $out = curl_exec($curl); // delivery data of SMS (данные до доставке SMS) // curl_close($curl); } else { switch ($response['error']) { case 'cash_close': echo 'Cмена закрыта'; echo "<script>jQuery(document).ready(function ($) { var popup_id = 948; MasterPopups.open(popup_id); //Or using a jQuery selector $('.mpp-popup-' + popup_id).MasterPopups(); }); </script>"; $order->update_status('failed'); break; case 'invalid_product_keys': echo 'Неверный массив товаров'; $order->update_status('failed'); break; } } } /* * If order has been cancelled or failed, e-mails will be not sent * Если заказ отменен или не удался, не отправлять сообщения на e-mail */ add_action('woocommerce_order_status_changed', 'custom_send_email_notifications', 10, 4); function custom_send_email_notifications($order_id, $old_status, $new_status, $order) { if ($new_status == 'cancelled' || $new_status == 'failed') { $wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances $customer_email = $order->get_billing_email(); // The customer email } if ($new_status == 'cancelled') { // change the recipient of this instance $wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email; // Sending the email from this instance $wc_emails['WC_Email_Cancelled_Order']->trigger($order_id); } elseif ($new_status == 'failed') { // change the recipient of this instance $wc_emails['WC_Email_failed_Order']->recipient = $customer_email; // Sending the email from this instance $wc_emails['WC_Email_failed_Order']->trigger($order_id); } }