Skip to content

Add robokassa_receipt_pre filter for custom receipt generation#48

Open
tikhomirov wants to merge 10 commits intorobokassa:masterfrom
tikhomirov:feature/add-receipt-pre-filter
Open

Add robokassa_receipt_pre filter for custom receipt generation#48
tikhomirov wants to merge 10 commits intorobokassa:masterfrom
tikhomirov:feature/add-receipt-pre-filter

Conversation

@tikhomirov
Copy link

Описание

Добавлен фильтр robokassa_receipt_pre в начало функции createRobokassaReceipt(),
который позволяет разработчикам полностью переопределить логику формирования чека.

Зачем это нужно

Текущий фильтр wc_robokassa_receipt вызывается в конце функции и не передаёт $order_id.
Это делает невозможным:

  • Корректную обработку скидок на товары
  • Кастомную логику расчёта цен
  • Интеграцию с другими плагинами без хаков

Использование

add_filter('robokassa_receipt_pre', function($receipt, $order_id) {
    $order = wc_get_order($order_id);
    // Кастомная логика формирования чека
    return $receipt;
}, 10, 2);

Aleksei Tikhomirov and others added 9 commits September 21, 2024 11:17
Добавлен фильтр для итоговых данных чека
Исправлена совместимость виджета с PHP 8.1+
- Незначительные исправления
# Conflicts:
#	data/robokassa_DEBUG.txt
#	wp_robokassa.php
# Conflicts:
#	main_settings_credit.php
#	wp_robokassa.php
@tikhomirov tikhomirov force-pushed the feature/add-receipt-pre-filter branch 3 times, most recently from 83d45ac to 860f92d Compare February 26, 2026 09:12
This PR adds two filters to allow developers to customize receipt generation:

1. `robokassa_receipt_pre` - Called at the start of createRobokassaReceipt().
   Return non-null value to bypass default receipt creation.

2. `wc_robokassa_receipt` - Now passes $order_id as second argument.
   Allows modifying the generated receipt with access to order data.

Both filters pass $order_id, enabling:
- Custom pricing calculations (discounts, dynamic prices)
- Integration with other plugins without core modifications
- Access to order data for receipt customization

Usage examples:

// Pre-filter: complete override
add_filter('robokassa_receipt_pre', function($receipt, $order_id) {
    $order = wc_get_order($order_id);
    // Custom receipt generation logic
    return $receipt;
}, 10, 2);

// Post-filter: modify existing receipt
add_filter('wc_robokassa_receipt', function($receipt, $order_id) {
    $order = wc_get_order($order_id);
    // Modify receipt items, totals, etc.
    return $receipt;
}, 10, 2);

Backward compatible: existing filters without order_id argument will continue to work.
@tikhomirov tikhomirov force-pushed the feature/add-receipt-pre-filter branch from 860f92d to 19f08db Compare February 26, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant