• skerrrr

    (@skerrrr)


    Hello! I will be very grateful if someone will help me to fix the issue.

    I am using Ocean WP theme on my website and I need to integrate woocommerce orders to Bitrix24 CRM system. So I used the code and pasted it in function.php file in Theme editor. But I got this notification — “Your PHP code changes were not applied due to an error on line 1169 of file wp-content/themes/oceanwp/functions.php. Please fix and try saving again. syntax error, unexpected token “@”, expecting “)”.

    But symbol “@” is a part of user login (email) I need to use for integration. Can someone tell me how can I fix this issue? Here is the code I am using:

    add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
    function my_custom_tracking( $order_id ) {
    // Подключаемся к серверу CRM
    define('CRM_HOST', '***********.bitrix24.ru'); // Ваш домен CRM системы
    define('CRM_PORT', '443'); // Порт сервера CRM. Установлен по умолчанию
    define('CRM_PATH', '/crm/configs/import/lead.php'); // Путь к компоненту lead.rest


    // Авторизуемся в CRM под необходимым пользователем:
    // 1. Указываем логин пользователя Вашей CRM по управлению лидами
    define('CRM_LOGIN', ‘******[email protected]’);
    // 2. Указываем пароль пользователя Вашей CRM по управлению лидами
    define('CRM_PASSWORD', ‘*****t07.’);

    // Получаем информации по заказу
    $order = wc_get_order( $order_id );
    $order_data = $order->get_data();

    // Получаем базовую информация по заказу
    $order_id = $order_data['id'];
    $order_currency = $order_data['currency'];
    $order_payment_method_title = $order_data['payment_method_title'];
    $order_shipping_totale = $order_data['shipping_total'];
    $order_total = $order_data['total'];

    $order_base_info = "<hr><strong>Общая информация по заказу</strong><br>
    ID заказа: $order_id<br>
    Валюта заказа: $order_currency<br>
    Метода оплаты: $order_payment_method_title<br>
    Стоимость доставки: $order_shipping_totale<br>
    Итого с доставкой: $order_total<br>";

    // Получаем информация по клиенту
    $order_customer_id = $order_data['customer_id'];
    $order_customer_ip_address = $order_data['customer_ip_address'];
    $order_billing_first_name = $order_data['billing']['first_name'];
    $order_billing_last_name = $order_data['billing']['last_name'];
    $order_billing_email = $order_data['billing']['email'];
    $order_billing_phone = $order_data['billing']['phone'];

    $order_client_info = "<hr><strong>Информация по клиенту</strong><br>
    ID клиента = $order_customer_id<br>
    IP адрес клиента: $order_customer_ip_address<br>
    Имя клиента: $order_billing_first_name<br>
    Фамилия клиента: $order_billing_last_name<br>
    Email клиента: $order_billing_email<br>
    Телефон клиента: $order_billing_phone<br>";

    // Получаем информацию по доставке
    $order_shipping_address_1 = $order_data['shipping']['address_1'];
    $order_shipping_address_2 = $order_data['shipping']['address_2'];
    $order_shipping_city = $order_data['shipping']['city'];
    $order_shipping_state = $order_data['shipping']['state'];
    $order_shipping_postcode = $order_data['shipping']['postcode'];
    $order_shipping_country = $order_data['shipping']['country'];

    $order_shipping_info = "<hr><strong>Информация по доставке</strong><br>
    Страна доставки: $order_shipping_state<br>
    Город доставки: $order_shipping_city<br>
    Индекс: $order_shipping_postcode<br>
    Адрес доставки 1: $order_shipping_address_1<br>
    Адрес доставки 2: $order_shipping_address_2<br>";

    // Получаем информации по товару
    $order->get_total();
    $line_items = $order->get_items();
    foreach ( $line_items as $item ) {
    $product = $order->get_product_from_item( $item );
    $sku = $product->get_sku(); // артикул товара
    $id = $product->get_id(); // id товара
    $name = $product->get_name(); // название товара
    $description = $product->get_description(); // описание товара
    $stock_quantity = $product->get_stock_quantity(); // кол-во товара на складе
    $qty = $item['qty']; // количество товара, которое заказали
    $total = $order->get_line_total( $item, true, true ); // стоимость всех товаров, которые заказали, но без учета доставки

    $product_info[] = "<hr><strong>Информация о товаре</strong><br>
    Название товара: $name<br>
    ID товара: $id<br>
    Артикул: $sku<br>
    Описание: $description<br>
    Заказали (шт.): $qty<br>
    Наличие (шт.): $stock_quantity<br>
    Сумма заказа (без учета доставки): $total;";
    }

    $product_base_infо = implode('<br>', $product_info);

    $subject = "Заказ с сайта № $order_id";

    // Формируем параметры для создания лида в переменной $postData = array
    $postData = array(
    'TITLE' => $subject,
    'COMMENTS' => $order_base_info.' '.$order_client_info.' '.$order_shipping_info.' '.$product_base_infо
    );

    // Передаем данные из Woocommerce в Bitrix24
    if (defined('CRM_AUTH')) {
    $postData['AUTH'] = CRM_AUTH;
    } else {
    $postData['LOGIN'] = CRM_LOGIN;
    $postData['PASSWORD'] = CRM_PASSWORD;
    }

    $fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30);
    if ($fp) {
    $strPostData = '';
    foreach ($postData as $key => $value)
    $strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value);

    $str = "POST ".CRM_PATH." HTTP/1.0\r\n";
    $str .= "Host: ".CRM_HOST."\r\n";
    $str .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $str .= "Content-Length: ".strlen($strPostData)."\r\n";
    $str .= "Connection: close\r\n\r\n";

    $str .= $strPostData;

    fwrite($fp, $str);

    $result = '';
    while (!feof($fp))
    {
    $result .= fgets($fp, 128);
    }
    fclose($fp);

    $response = explode("\r\n\r\n", $result);

    $output = '<pre>'.print_r($response[1], 1).'</pre>';
    } else {
    echo 'Connection Failed! '.$errstr.' ('.$errno.')';
    }
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Shahin

    (@skalanter)

    Hello @skerrrr,

    Thank you for reaching out,

    Regarding the service you are using, we don’t have experience integrating it.
    In this case, we can’t definitively provide a solution for it.

    Regarding the error you encountered; the error is a syntax error in the PHP and that occurs because the @ symbol is being interpreted as a PHP function call but it is a part of the user’s email. To solve it, you need to escape the @ symbol using the addslashes() function. Here’s the updated code:

    // Escape the "@" symbol in the email
    $order_billing_email = addslashes($order_billing_email);

    The addslashes() function adds backslashes (\) to escape special characters in PHP, like “, ‘, and @, preventing misinterpretation.

    Note 1: If you’re not already familiar with PHP, contacting a PHP expert might be the best course of action.

    Note 2: Since you mentioned a premium service/plugin, please remember that we cannot solve issues related to premium plugins, tools, or services according to the forum rules. Please read the forum guidelines:
    https://www.ads-software.com/support/guidelines/#do-not-post-about-commercial-products

    I hope it helps.
    Best Regards

Viewing 1 replies (of 1 total)
  • The topic ‘Theme Editor — syntax error, unexpected token “@”, expecting “)”’ is closed to new replies.