Skip to content

Commit 19f08db

Browse files
committed
Add filters with order_id for custom receipt generation
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.
1 parent b5a966e commit 19f08db

2 files changed

Lines changed: 16 additions & 49 deletions

File tree

data/robokassa_DEBUG.txt

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +0,0 @@
1-
03.12.2024 22:14:06 (1733253246) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
2-
03.12.2024 22:15:13 (1733253313) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
3-
06.12.2024 14:51:00 (1733485860) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
4-
06.12.2024 14:51:27 (1733485887) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
5-
06.12.2024 15:02:31 (1733486551) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
6-
06.12.2024 23:14:04 (1733516044) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
7-
06.12.2024 23:14:11 (1733516051) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
8-
23.12.2024 16:21:37 (1734960097) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
9-
23.12.2024 16:30:38 (1734960638) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
10-
23.12.2024 16:47:32 (1734961652) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
11-
23.12.2024 17:04:30 (1734962670) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
12-
24.12.2024 13:08:29 (1735034909) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
13-
26.12.2024 18:54:21 (1735228461) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
14-
28.12.2024 17:00:54 (1735394454) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
15-
28.12.2024 17:02:12 (1735394532) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
16-
28.12.2024 20:24:51 (1735406691) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
17-
28.12.2024 20:25:59 (1735406759) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
18-
28.12.2024 20:29:28 (1735406968) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
19-
28.12.2024 20:29:55 (1735406995) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
20-
28.12.2024 20:35:51 (1735407351) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
21-
28.12.2024 20:39:48 (1735407588) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
22-
28.12.2024 20:47:56 (1735408076) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
23-
28.12.2024 20:49:59 (1735408199) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
24-
28.12.2024 20:56:22 (1735408582) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
25-
28.12.2024 20:56:33 (1735408593) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
26-
28.12.2024 20:56:43 (1735408603) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
27-
28.12.2024 20:56:52 (1735408612) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
28-
28.12.2024 20:57:02 (1735408622) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
29-
28.12.2024 20:57:12 (1735408632) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
30-
28.12.2024 20:57:24 (1735408644) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
31-
28.12.2024 20:57:34 (1735408654) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
32-
28.12.2024 20:57:44 (1735408664) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
33-
28.12.2024 20:57:54 (1735408674) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
34-
28.12.2024 20:58:05 (1735408685) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
35-
28.12.2024 20:58:07 (1735408687) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
36-
28.12.2024 21:00:57 (1735408857) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
37-
28.12.2024 21:16:03 (1735409763) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
38-
28.12.2024 21:18:47 (1735409927) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
39-
28.12.2024 22:15:22 (1735413322) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
40-
28.12.2024 22:27:21 (1735414041) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
41-
28.12.2024 22:30:59 (1735414259) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
42-
28.12.2024 22:34:00 (1735414440) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
43-
28.12.2024 22:35:50 (1735414550) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
44-
28.12.2024 22:36:22 (1735414582) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
45-
13.01.2025 19:10:00 (1736784600) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
46-
13.01.2025 19:29:30 (1736785770) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
47-
17.01.2025 16:00:49 (1737118849) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken
48-
17.01.2025 16:44:38 (1737121478) : Robokassa: Payment method is not advance, full_prepayment, or prepayment, no action taken

wp_robokassa.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,21 @@ function getRobokassaPasses()
618618
*/
619619
function createRobokassaReceipt($order_id)
620620
{
621+
/**
622+
* Filter to allow custom receipt generation.
623+
* Return a non-null value to bypass default receipt creation.
624+
*
625+
* @param array|null $pre_receipt Custom receipt data or null to use default.
626+
* @param int $order_id Order ID.
627+
*
628+
* @since 1.6.6
629+
*/
630+
$pre_receipt = apply_filters('robokassa_receipt_pre', null, $order_id);
631+
632+
if ($pre_receipt !== null) {
633+
return $pre_receipt;
634+
}
635+
621636
global $woocommerce;
622637
$order = new WC_Order($order_id);
623638

@@ -722,7 +737,7 @@ function createRobokassaReceipt($order_id)
722737
robokassa_payment_DEBUG('Robokassa: общая сумма чека (' . $total_receipt . ') НЕ совпадает с общей суммой заказа (' . $total_order . ')');
723738
}
724739

725-
return apply_filters('wc_robokassa_receipt', $receipt);
740+
return apply_filters('wc_robokassa_receipt', $receipt, $order_id);
726741
}
727742

728743
/**

0 commit comments

Comments
 (0)