-
Notifications
You must be signed in to change notification settings - Fork 77
Fix: exclude POS cash orders from vendor withdrawable balance #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,10 @@ public function __construct() { | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // If vendor created via REST API | ||||||||||||||||||||||||||||||||||||||||||||||||
| add_action( 'dokan_new_vendor', [ $this, 'after_create_vendor_via_rest' ], 15 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Exclude wepos_cash payments from vendor withdrawal balance | ||||||||||||||||||||||||||||||||||||||||||||||||
| add_filter( 'dokan_order_should_exclude_from_vendor_balance', [ $this, 'exclude_wepos_cash_payment' ], 10, 5 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| add_filter( 'dokan_order_refund_should_exclude_from_vendor_balance', [ $this, 'prevent_wepos_cash_refund_deduction' ], 10, 6 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -163,4 +167,54 @@ public function add_dokan_settings( $settings_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return $settings_fields; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Exclude wepos_cash payments from vendor withdrawal balance | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * When a payment is made via wepos_cash method, exclude it from | ||||||||||||||||||||||||||||||||||||||||||||||||
| * the vendor's withdrawal balance calculation. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @since 1.3.3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param bool $should_exclude Whether to exclude the payment. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param WC_Order $order Order object. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param int $order_id Order ID. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param string $new_status New order status. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param bool $exclude_cod Whether exclude COD option is enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @return bool True if payment should be excluded, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| public function exclude_wepos_cash_payment( $should_exclude, $order, $order_id, $new_status, $exclude_cod ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if the payment method is wepos_cash | ||||||||||||||||||||||||||||||||||||||||||||||||
| if ( 'wepos_cash' === $order->get_payment_method() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return $should_exclude; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Prevent reducing refund amount from vendor balance for wepos_cash payments | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * When a refund is processed for an order paid via wepos_cash method, | ||||||||||||||||||||||||||||||||||||||||||||||||
| * prevent deducting the refund amount from the vendor's balance. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @since 1.3.3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param bool $should_exclude Whether to exclude from balance deduction. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param WC_Order $order Order object. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param int $order_id Order ID. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param string $new_status New order status. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @param bool $exclude_cod Whether exclude COD option is enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||
| * @return bool True if refund should not reduce vendor balance, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| public function prevent_wepos_cash_refund_deduction( $should_exclude, $order, $order_id, $new_status, $exclude_cod, $refund_order ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if the payment method is wepos_cash | ||||||||||||||||||||||||||||||||||||||||||||||||
| if ( 'wepos_cash' === $order->get_payment_method() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return $should_exclude; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+187
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for the filter definition and usage
rg -n "dokan_order_should_exclude_from_vendor_balance" -C3Repository: getdokan/wepos Length of output: 506 🏁 Script executed: #!/bin/bash
# Search for where the filter is applied/called
rg -n "apply_filters.*dokan_order_should_exclude_from_vendor_balance" -C5Repository: getdokan/wepos Length of output: 40 🏁 Script executed: #!/bin/bash
# Search for other uses of apply_filters to understand the pattern
rg -n "apply_filters.*vendor_balance" -C3Repository: getdokan/wepos Length of output: 40 🏁 Script executed: #!/bin/bash
# Check composer.json for Dokan dependency
cat composer.json | grep -A5 "dokan" || echo "No composer.json or dokan not listed"Repository: getdokan/wepos Length of output: 94 🌐 Web query:
💡 Result: I searched the getdokan/dokan GitHub repository and found no occurrences of the identifier "dokan_order_should_exclude_from_vendor_balance". Source: repository files/index. [1] Would you like me to search other repos, issues, or the wider web for that filter name? [1] https://github.com/getdokan/dokan 🏁 Script executed: #!/bin/bash
# Search for any apply_filters in wepos repo
rg -n "apply_filters" includes/ | head -20Repository: getdokan/wepos Length of output: 2631 🌐 Web query:
💡 Result: I couldn't find any public Dokan doc or code reference for a filter named exactly dokan_order_should_exclude_from_vendor_balance. Dokan does expose functional filters and seller hooks (see Dokan dev docs). [1][2] If that filter exists in your installed Dokan version (custom/third-party or newer internal hook), you can use it like any WP filter. Example — add to your theme/plugin: add_filter( 'dokan_order_should_exclude_from_vendor_balance', 'my_dokan_exclude_order_from_vendor_balance', 10, 2 ); } Notes:
References:
Sources: 🏁 Script executed: #!/bin/bash
# Search for other methods that use $order parameter or get_payment_method
rg -n "get_payment_method|WC_Order" includes/Dokan.php -C2Repository: getdokan/wepos Length of output: 602 🏁 Script executed: #!/bin/bash
# Check other methods in Dokan.php
rg -n "public function" includes/Dokan.php -A10 | head -50Repository: getdokan/wepos Length of output: 1928 🏁 Script executed: #!/bin/bash
# View the full exclude_wepos_cash_payment method with more context
sed -n '170,200p' includes/Dokan.phpRepository: getdokan/wepos Length of output: 995 Add defensive guard before calling 🔧 Suggested fix public function exclude_wepos_cash_payment( $should_exclude, $order, $order_id, $new_status, $exclude_cod ) {
+ if ( ! $order instanceof \WC_Order ) {
+ $order = $order_id ? wc_get_order( $order_id ) : null;
+ if ( ! $order ) {
+ return $should_exclude;
+ }
+ }
+
// Check if the payment method is wepos_cash
if ( $order->get_payment_method() === 'wepos_cash' ) {
return true;
}
return $should_exclude;
}Optionally suppress PHPMD unused-parameter warnings ( 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PHPMD (2.15.0)186-186: Avoid unused parameters such as '$order_id'. (undefined) (UnusedFormalParameter) 186-186: Avoid unused parameters such as '$new_status'. (undefined) (UnusedFormalParameter) 186-186: Avoid unused parameters such as '$exclude_cod'. (undefined) (UnusedFormalParameter) 🤖 Prompt for AI Agents
Comment on lines
+196
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add defensive type check and fix incomplete docblock. This method has the same vulnerability as Additionally, the docblock is missing the 🔧 Suggested fix /**
* Prevent reducing refund amount from vendor balance for wepos_cash payments
*
* When a refund is processed for an order paid via wepos_cash method,
* prevent deducting the refund amount from the vendor's balance.
*
* `@since` 1.3.3
*
* `@param` bool $should_exclude Whether to exclude from balance deduction.
* `@param` WC_Order $order Order object.
* `@param` int $order_id Order ID.
* `@param` string $new_status New order status.
* `@param` bool $exclude_cod Whether exclude COD option is enabled.
+ * `@param` WC_Order $refund_order Refund order object.
*
* `@return` bool True if refund should not reduce vendor balance, false otherwise.
*/
public function prevent_wepos_cash_refund_deduction( $should_exclude, $order, $order_id, $new_status, $exclude_cod, $refund_order ) {
+ if ( ! $order instanceof \WC_Order ) {
+ $order = $order_id ? wc_get_order( $order_id ) : null;
+ if ( ! $order ) {
+ return $should_exclude;
+ }
+ }
+
// Check if the payment method is wepos_cash
if ( 'wepos_cash' === $order->get_payment_method() ) {
return true;
}
return $should_exclude;
}🧰 Tools🪛 PHPMD (2.15.0)212-212: Avoid unused parameters such as '$order_id'. (undefined) (UnusedFormalParameter) 212-212: Avoid unused parameters such as '$new_status'. (undefined) (UnusedFormalParameter) 212-212: Avoid unused parameters such as '$exclude_cod'. (undefined) (UnusedFormalParameter) 212-212: Avoid unused parameters such as '$refund_order'. (undefined) (UnusedFormalParameter) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: getdokan/wepos
Length of output: 849
Confirm this
dokan_order_should_exclude_from_vendor_balancefilter is supported by your Dokan version.The filter registration is syntactically correct, but this filter does not exist in the current codebase—it must be provided by the Dokan plugin dependency. If your version of Dokan does not include this filter, the callback will never be invoked and vendor cash exclusion logic will not execute. Verify your Dokan version (or premium/custom build) actually applies this filter before deploying.
🤖 Prompt for AI Agents