Skip to content

Fix: exclude POS cash orders from vendor withdrawable balance - #3079

Merged
MdAsifHossainNadim merged 5 commits into
developfrom
fix/pos-cash-order-vendor-balance
Jan 27, 2026
Merged

Fix: exclude POS cash orders from vendor withdrawable balance#3079
MdAsifHossainNadim merged 5 commits into
developfrom
fix/pos-cash-order-vendor-balance

Conversation

@Shamim-97

@Shamim-97 Shamim-97 commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Refactor
    • Vendor payout calculation now supports configurable handling of Cash on Delivery (COD) exclusions for both order processing and refunds.
    • Administrators can control whether COD orders are excluded from vendor balances; default behavior and existing safeguards remain unchanged.
    • A new filterable hook allows overriding the exclusion decision during order and refund flows.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 19, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaces hardcoded COD-exclusion checks with computed flags passed through two new filters—dokan_order_should_exclude_from_vendor_balance and dokan_order_refund_should_exclude_from_vendor_balance—and uses the (possibly filtered) result to preserve early-return behavior when excluding COD orders from vendor balance logic.

Changes

Cohort / File(s) Summary
COD exclusion filter flow
includes/Order/Hooks.php, includes/Order/RefundHandler.php
Replaces direct COD-method checks with a computed $should_exclude_cod_payment and applies filters dokan_order_should_exclude_from_vendor_balance and dokan_order_refund_should_exclude_from_vendor_balance. Passes relevant context (order, order_id, new_status, option flag, refund_order) to filters and uses the filtered boolean to decide early-return exclusion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Need Dev Review Only

Suggested reviewers

  • mrabbani

Poem

🐰 I hopped through hooks with careful paws,
I left a filter for thoughtful laws.
COD now asks before it hides,
Balances mend where cash resides—
🥕 a small tweak, celebrated cause.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding filterable hooks to exclude POS cash (COD) orders from vendor withdrawable balance calculations.
Description check ✅ Passed The PR description follows the template with related issues and linked PRs filled in; however, key sections like 'Changes proposed', 'How to test', changelog entry, and before/after comparisons lack substantive detail.
Linked Issues check ✅ Passed The changes introduce filterable hooks (dokan_order_should_exclude_from_vendor_balance and dokan_order_refund_should_exclude_from_vendor_balance) allowing POS cash/COD orders to be excluded from vendor balance calculations, directly addressing issue #5333's requirement to exclude such orders.
Out of Scope Changes check ✅ Passed Both modified files (Hooks.php and RefundHandler.php) make focused changes to add filterable logic for excluding COD orders from vendor balance, staying within the scope of addressing POS cash order exclusion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@includes/Order/Hooks.php`:
- Around line 128-138: Replace the placeholder `@since` DOKAN_SINCE with the
actual release version for this change, and update the docblock to generalize
COD-specific language: change the overall description to "Filter whether the
order should be excluded from vendor withdrawal balance" (already present) and
update the param descriptions for $should_exclude_cod_payment and
$exclude_cod_payment to say "Whether to exclude the order from the vendor
balance" (or similar generic wording) instead of referencing COD; keep the
WC_Order $order and int $order_id descriptions unchanged and ensure the param
names in the docblock match the actual parameter names used by the filter/hook
in Hooks.php.
🧹 Nitpick comments (1)
includes/Order/Hooks.php (1)

139-149: Normalize the filter result to a boolean.

This avoids surprises if a hook returns a non-boolean truthy value.

Suggested change
-$should_exclude_cod_payment = apply_filters(
+$should_exclude_cod_payment = (bool) apply_filters(
     'dokan_order_should_exclude_from_vendor_balance',
     $should_exclude_cod_payment,
     $order,
     $order_id,
     $new_status,
     $exclude_cod_payment
 );

Comment thread includes/Order/Hooks.php
@Shamim-97 Shamim-97 self-assigned this Jan 19, 2026
@Shamim-97 Shamim-97 added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jan 19, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@includes/Order/RefundHandler.php`:
- Line 90: Remove the trailing end-of-line whitespace from the docblock line
containing "@return bool" in the RefundHandler class (file
includes/Order/RefundHandler.php) so PHPCS no longer flags the EOL whitespace;
locate the docblock above the relevant method in the RefundHandler class and
delete the extra space character at the end of the "@return bool" line.

Comment thread includes/Order/RefundHandler.php Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
includes/Order/RefundHandler.php (3)

210-210: Pre-existing bug: Missing method call parentheses.

This line appears to have a pre-existing bug - $refund_order->get_id should be $refund_order->get_id(). While not introduced by this PR, it will cause a runtime error when this logging code is executed.

🐛 Suggested fix
-                    $refund_order->get_id, $vendor_refund_amount
+                    $refund_order->get_id(), $vendor_refund_amount

225-227: Pre-existing logic issue: Condition appears inverted.

This pre-existing code overwrites the refund reason with a generic message when a reason already exists. The condition likely should be negated (! $refund_reason) to set the default only when no reason is provided.

🐛 Suggested fix
-        if ( $refund_reason ) {
+        if ( ! $refund_reason ) {
             $refund_reason = __( 'Refunded by Dokan', 'dokan-lite' );
         }

98-128: Address the misleading comment about filter name consistency.

The implementation correctly uses two distinct filters for different contexts:

  • dokan_order_should_exclude_from_vendor_balance (Hooks.php) for order status updates
  • dokan_order_refund_should_exclude_from_vendor_balance (RefundHandler.php) for refund handling

However, the comment at line 109 states "Use the exact same filter name for consistency across the whole system" which is misleading since the filter name is actually different. Using separate filter names for these distinct contexts is appropriate design. Clarify the comment to reflect that this is a refund-specific filter with additional context parameters like $refund_order.

The implementation itself properly enables extensibility for wePOS and other plugins to override exclusion logic via the filter hook.

Comment thread includes/Order/RefundHandler.php Outdated
Comment thread includes/Order/RefundHandler.php

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
includes/Order/RefundHandler.php (1)

231-233: Pre-existing bug: Inverted condition overwrites valid refund reasons.

This logic appears to be inverted. Currently, if $refund_reason is truthy (has a value), it gets overwritten with the default message. The condition should be negated to only set the default when the reason is empty.

🐛 Proposed fix
-        if ( $refund_reason ) {
+        if ( ! $refund_reason ) {
             $refund_reason = __( 'Refunded by Dokan', 'dokan-lite' );
         }
🤖 Fix all issues with AI agents
In `@includes/Order/RefundHandler.php`:
- Around line 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.

Comment on lines +108 to +128
/**
* 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 string $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,
);

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.

@dev-shahed dev-shahed added 🎉 QA Approved This PR is approved by the QA team and removed Needs: Testing This requires further testing labels Jan 27, 2026
@MdAsifHossainNadim MdAsifHossainNadim added Dev Review Done and removed Needs: Dev Review It requires a developer review and approval labels Jan 27, 2026
@MdAsifHossainNadim
MdAsifHossainNadim merged commit 2ac942c into develop Jan 27, 2026
1 of 6 checks passed
@MdAsifHossainNadim
MdAsifHossainNadim deleted the fix/pos-cash-order-vendor-balance branch January 27, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev Review Done 🎉 QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants