Setting up SMS notifications for abandoned carts in 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1177
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Configuring Abandoned Cart SMS Notifications in 1C-Bitrix

An abandoned cart SMS is a more aggressive tool than email: it is opened in 95% of cases versus 20–30% for email. That is precisely why it must be used carefully — only for users who have given explicit consent, and only once per cycle — without follow-up SMS reminders.

When SMS Is Justified

The SMS channel for abandoned carts delivers results in several scenarios:

  • High average order value (from 3,000 RUB) — the value of the reminder outweighs the cost of the SMS
  • The user has not opened the email within 3–4 hours
  • Product categories with high impulse demand (electronics, clothing)

For low-value goods, the cost of the SMS channel (3–8 RUB per message) cancels out the profit from cart recovery.

Getting the User's Phone Number from Bitrix

The phone number is taken from the user profile. 1C-Bitrix stores it in user fields (b_user_field) or in order properties (b_sale_order_props_value):

function getUserPhone(int $userId): string
{
    // Method 1: from the UF_PHONE user field
    $user = \Bitrix\Main\UserTable::getById($userId)->fetch();
    if (!empty($user['UF_PHONE'])) return $user['UF_PHONE'];

    // Method 2: from the user's last order
    $order = \Bitrix\Sale\Order::getList([
        'filter' => ['USER_ID' => $userId],
        'order'  => ['DATE_INSERT' => 'DESC'],
        'limit'  => 1,
        'select' => ['ID'],
    ])->fetch();

    if (!$order) return '';

    $orderObj = \Bitrix\Sale\Order::load($order['ID']);
    foreach ($orderObj->getPropertyCollection() as $prop) {
        if ($prop->getField('CODE') === 'PHONE') {
            return (string)$prop->getValue();
        }
    }

    return '';
}

Connecting an SMS Gateway

1C-Bitrix has a built-in SMS dispatch module (main.smsmanager), but it is designed for standard notifications. For abandoned carts, direct API integration with an SMS provider is preferable.

Popular providers with REST APIs: SMS.ru, SMSC.ru, MTS Communicator, SMPP.

Example integration with SMS.ru:

class SmsRuClient
{
    private string $apiId;

    public function __construct(string $apiId)
    {
        $this->apiId = $apiId;
    }

    public function send(string $phone, string $message, string $from = 'SHOP'): bool
    {
        $phone = preg_replace('/[^0-9]/', '', $phone);
        if (strlen($phone) === 10) $phone = '7' . $phone;

        $ch = curl_init('https://sms.ru/sms/send');
        curl_setopt_array($ch, [
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => http_build_query([
                'api_id' => $this->apiId,
                'to'     => $phone,
                'msg'    => $message,
                'from'   => $from,
                'json'   => 1,
            ]),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 10,
        ]);

        $response = json_decode(curl_exec($ch), true);
        curl_close($ch);

        return isset($response['status']) && $response['status'] === 'OK';
    }
}

Abandoned Cart SMS Text

SMS is limited to 160 characters (Cyrillic text: 70 characters per segment). The text must be short and include a direct link:

function buildCartSmsText(string $userName, float $cartTotal, string $cartUrl): string
{
    $shortUrl = shortenUrl($cartUrl); // URL shortener or your own domain
    $total    = number_format($cartTotal, 0, '.', ' ');

    return "{$userName}, you have items in your cart worth {$total}. Complete your order: {$shortUrl}";
}

Do not list specific products — 70 characters won't allow for it. Include the total amount — this provides context.

SMS Sending Agent

function sendAbandonedCartSms(): string
{
    $smsClient = new SmsRuClient(getenv('SMSRU_API_ID'));

    // Select carts: email sent 3 hours ago, no SMS yet
    $candidates = AbandonedCartTable::getList([
        'filter' => [
            'STATUS'         => 'email_sent',
            '<EMAIL_SENT_AT' => new \Bitrix\Main\Type\DateTime('-3 hours'),
            '=SMS_SENT_AT'   => false,
        ],
        'limit' => 20, // no more than 20 at a time — control gateway load
    ])->fetchAll();

    foreach ($candidates as $row) {
        // Check SMS consent
        $user = \Bitrix\Main\UserTable::getById($row['USER_ID'])->fetch();
        if (empty($user['UF_SMS_CONSENT'])) continue;

        $phone = getUserPhone($row['USER_ID']);
        if (!$phone) continue;

        // Check if an order was placed after the email
        if (hasRecentOrder($row['USER_ID'])) {
            AbandonedCartTable::update($row['ID'], ['STATUS' => 'recovered']);
            continue;
        }

        $basket  = \Bitrix\Sale\Basket::loadItemsForFUser($row['FUSER_ID'], SITE_ID);
        if ($basket->isEmpty()) continue;

        $smsText = buildCartSmsText($user['NAME'], $basket->getPrice(), '/basket/');
        $sent    = $smsClient->send($phone, $smsText);

        AbandonedCartTable::update($row['ID'], [
            'STATUS'     => $sent ? 'sms_sent' : 'sms_failed',
            'SMS_SENT_AT' => $sent ? new \Bitrix\Main\Type\DateTime() : null,
        ]);
    }

    return __FUNCTION__ . '();';
}

Consent Management

The SMS marketing consent field (UF_SMS_CONSENT) must be set during registration or in the user account — via an explicit checkbox: "I want to receive SMS with personalized offers." Sending SMS without explicit consent violates Federal Law No. 38.

Timelines: SMS gateway setup and sending agent — 1–2 days. With consent management and registration form integration — 2–3 days.