diff --git a/includes/Order/Hooks.php b/includes/Order/Hooks.php index 1841244af6..bf6c2fac5b 100644 --- a/includes/Order/Hooks.php +++ b/includes/Order/Hooks.php @@ -123,7 +123,29 @@ public function on_order_status_change( $order_id, $old_status, $new_status, $or */ $exclude_cod_payment = 'on' === dokan_get_option( 'exclude_cod_payment', 'dokan_withdraw', 'off' ); - if ( $exclude_cod_payment && 'cod' === $order->get_payment_method() ) { + $should_exclude_cod_payment = $exclude_cod_payment && 'cod' === $order->get_payment_method(); + + /** + * Filter whether the order should be excluded from vendor withdrawal balance. + * + * @since DOKAN_SINCE + * + * @param bool $should_exclude_cod_payment Whether to exclude COD payment from balance. + * @param WC_Order $order Order object. + * @param int $order_id Order ID. + * @param string $new_status New order status. + * @param bool $exclude_cod_payment Whether exclude COD option is enabled. + */ + $should_exclude_cod_payment = apply_filters( + 'dokan_order_should_exclude_from_vendor_balance', + $should_exclude_cod_payment, + $order, + $order_id, + $new_status, + $exclude_cod_payment + ); + + if ( $should_exclude_cod_payment ) { return; } diff --git a/includes/Order/RefundHandler.php b/includes/Order/RefundHandler.php index 6b78da39e5..dd60866e50 100644 --- a/includes/Order/RefundHandler.php +++ b/includes/Order/RefundHandler.php @@ -95,17 +95,39 @@ public function exclude_cod_payment( $ret, $refund_order, $order ) { return $ret; } - // if cod is not payment method return - if ( 'cod' !== $order->get_payment_method() ) { - return $ret; - } + $order_id = $order->get_id(); + $new_status = $order->get_status(); + + $exclude_cod_option = 'on' === dokan_get_option( 'exclude_cod_payment', 'dokan_withdraw', 'off' ); /** - * If `exclude_cod_payment` is enabled, don't include the fund in vendor's refund balance. + * Calculate the default logic (Is it COD and is the option ON?) */ - $exclude_cod_payment = 'on' === dokan_get_option( 'exclude_cod_payment', 'dokan_withdraw', 'off' ); + $should_exclude_cod_payment = $exclude_cod_option && 'cod' === $order->get_payment_method(); + + /** + * Apply the filter so other plugins (like wePOS) can override this. + * Use the exact same filter name for consistency across the whole system. + * + * @since DOKAN_SINCE + * @param bool $should_exclude_cod_payment Whether to exclude the payment. + * @param WC_Order $order The main WooCommerce order object. + * @param int $order_id The ID of the main order. + * @param string $new_status The new status of the order. + * @param bool $exclude_cod_option The value of the 'exclude COD' setting. + * @param WC_Order $refund_order The specific refund order object. + */ + $should_exclude_cod_payment = apply_filters( + 'dokan_order_refund_should_exclude_from_vendor_balance', + $should_exclude_cod_payment, + $order, + $order_id, + $new_status, + $exclude_cod_option, + $refund_order, + ); - if ( $exclude_cod_payment ) { + if ( $should_exclude_cod_payment ) { return false; }