Skip to content

Commit 860f92d

Browse files
author
Aleksei Tikhomirov
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 860f92d

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

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)