Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion includes/Order/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Comment thread
MdAsifHossainNadim marked this conversation as resolved.
$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;
}

Expand Down
36 changes: 29 additions & 7 deletions includes/Order/RefundHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
add_filter( 'dokan_refund_should_insert_into_vendor_balance', [ $this, 'exclude_cod_payment' ], 10, 3 );
add_filter( 'dokan_vendor_earning_in_refund', [ $this, 'get_vendor_earning_in_refund' ], 10, 2 );
add_action( 'dokan_refund_adjust_vendor_balance', [ $this, 'insert_into_balance_table' ], 10, 3 );
// add_action( 'dokan_refund_adjust_dokan_orders', [ $this, 'update_order_amounts' ], 10, 3 );

Check failure on line 22 in includes/Order/RefundHandler.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Line indented incorrectly; expected at least 2 tabs, found 0
add_action( 'dokan_refund_after_dokan_orders_updated', [ $this, 'clear_order_caches' ], 10, 3 );
}

Expand Down Expand Up @@ -95,17 +95,39 @@
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.
*

Check failure on line 111 in includes/Order/RefundHandler.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
* @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 string $exclude_cod_option The value of the 'exclude COD' setting.
* @param WC_Order $refund_order The specific refund order object.
*/
Comment thread
Shamim-97 marked this conversation as resolved.
$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,
);
Comment on lines +108 to +128

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Docblock type mismatch for $exclude_cod_option parameter.

Line 117 documents $exclude_cod_option as string, but the variable is actually a bool (the result of 'on' === dokan_get_option(...)).

Also, ensure the @since DOKAN_SINCE placeholder is replaced with the actual version number before release.

📝 Proposed fix
         * `@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` string   $exclude_cod_option         The value of the 'exclude COD' setting.
+        * `@param` bool     $exclude_cod_option         Whether the 'exclude COD' setting is enabled.
         * `@param` WC_Order $refund_order               The specific refund order object.
         */
🤖 Prompt for AI Agents
In `@includes/Order/RefundHandler.php` around lines 108 - 128, The docblock for
the apply_filters call is wrong: $exclude_cod_option is documented as string but
is actually a bool (set via 'on' === dokan_get_option(...)); update the `@param`
type for $exclude_cod_option to bool and replace the placeholder `@since`
DOKAN_SINCE with the real release version, keeping the rest of the docblock and
the apply_filters call (dokan_order_refund_should_exclude_from_vendor_balance,
$should_exclude_cod_payment, $order, $order_id, $new_status,
$exclude_cod_option, $refund_order) unchanged so the signature and filter
behavior remain consistent.


if ( $exclude_cod_payment ) {
if ( $should_exclude_cod_payment ) {
return false;
}

Expand Down
Loading