Setting up time-of-day pricing 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
    1175
  • 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

Setting up time-based pricing in 1C-Bitrix

The standard catalog module lacks a mechanism to change product prices based on the time of day. Price types, discounts, markups — all are static entities not bound to time. Yet the task is real: night rates for delivery, happy hour for restaurants, peak markups for capacity-limited services. Implementation requires intervention in the price calculation logic at the event level.

Price calculation mechanism in the catalog

Product price goes through a chain: base price from b_catalog_price → discount application from b_catalog_discount → rounding → result. The \Bitrix\Catalog\Product\Price::getPrice() method returns the final price, but catalog discounts are applied based on user groups and conditions (order sum, product quantity), not time.

Entry point — the OnGetOptimalPrice event from the catalog module. The handler receives product ID, quantity, user groups, and can return an array with an overridden price. This is where time-based logic is injected.

Implementation through event handlers

Create a handler in init.php or through a custom module:

  1. Register the event: AddEventHandler('catalog', 'OnGetOptimalPrice', ...).
  2. Determine current hour: date('G') returns hour without leading zero (0–23). Account for server timezone — date_default_timezone_get() must match the business zone.
  3. Apply coefficient: night coefficient 0.85 for hours 22:00–06:00 is multiplied by base price. Coefficients are stored in b_option or in custom infoblock properties — depends on whether different rules are needed for different products.

Important: OnGetOptimalPrice handler is called every time price is displayed — in catalog, on product page, in cart. Don't make heavy requests in it. Cache coefficients in a static class variable or in \Bitrix\Main\Data\Cache with TTL of 300 seconds.

Caching and pitfalls

Composite cache and component caches by default don't account for time of day. The catalog.section component will cache a page with daytime prices, and a night visitor will see them until TTL expires.

Solution — add hour to cache key via CACHE_GROUPS parameter or through AddAdditionalCacheID() in component_epilog.php. Cache will reset every hour — acceptable for most shops.

For composite cache use dynamic area <bx:dynamic> around the price block. Price will be loaded via AJAX on each page view.

Displaying tariff information

Show users that price depends on time. Add to catalog.element component template a block with current tariff: "Night rate: 15% discount until 06:00". Calculate end time with server code and pass through $arResult. JavaScript countdown timer to tariff change increases transparency for buyers.