Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
42 changes: 42 additions & 0 deletions includes/Dashboard/Templates/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
add_action( 'dokan_settings_content_area_header', [ $this, 'render_settings_load_progressbar' ], 20 );
add_action( 'dokan_settings_content', [ $this, 'render_settings_content' ], 10 );
add_filter( 'dokan_payment_method_title', [ $this, 'get_method_frontend_title' ], 10, 2 );
add_filter( 'dokan_rest_store_settings_additional_fields', [ $this, 'add_payment_methods_to_rest_response' ], 10, 3 );
}

/**
Expand Down Expand Up @@ -479,6 +480,17 @@
}
}

// Validate Terms & Conditions: if enabled, content must not be empty
$enable_tnc = isset( $_POST['dokan_store_tnc_enable'] ) && 'on' === sanitize_text_field( wp_unslash( $_POST['dokan_store_tnc_enable'] ) );
if ( $enable_tnc ) {
$store_tnc = isset( $_POST['dokan_store_tnc'] ) ? wp_unslash( $_POST['dokan_store_tnc'] ) : '';

Check failure on line 486 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['dokan_store_tnc']
$store_tnc_clean = wp_strip_all_tags( $store_tnc );

Check failure on line 488 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
if ( empty( trim( $store_tnc_clean ) ) ) {
$error->add( 'dokan_tnc_content', __( 'Please add Terms & Conditions content before saving settings.', 'dokan-lite' ) );
}
}

if ( $error->get_error_codes() ) {
return $error;
}
Expand Down Expand Up @@ -864,11 +876,41 @@
*
* @return string
*/
public function get_method_frontend_title( $title, $method ) {

Check warning on line 879 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $method is never used
if ( 0 === stripos( $title, 'Dokan ' ) ) {
return substr( $title, 6 );
}

return $title;
}

/**
* Add payment methods data to REST API response for admin withdraw tab.
*
* @since 4.2.6
*
* @param array $additional_fields Additional fields to add to response.
* @param \WeDevs\Dokan\Vendor\Vendor $store Store object.
* @param \WP_REST_Request $request Request object.
*
* @return array
*/
public function add_payment_methods_to_rest_response( $additional_fields, $store, $request ) {

Check warning on line 898 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $request is never used
$vendor_id = method_exists( $store, 'get_id' ) ? (int) $store->get_id() : 0;

if ( $vendor_id > 0 ) {
// Get payment methods data using the same logic as vendor dashboard.
$payment_data = $this->get_seller_payment_methods( $vendor_id );

// Add flag to indicate if any withdraw method is globally available.
$additional_fields['withdraw_methods_available'] = ! empty( $payment_data['active_methods'] );

// Add payment method data.
$additional_fields['active_payment_methods'] = $payment_data['active_methods'];
$additional_fields['connected_methods'] = $payment_data['connected_methods'];
$additional_fields['disconnected_methods'] = $payment_data['disconnected_methods'];
}

return $additional_fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ function WithdrawPaymentRow( {
);
}

return settings.withdraw_options[ selectedMethod ];
return (
settings?.withdraw_options?.[ selectedMethod ] ??
settings?.connected_methods?.[ selectedMethod ]?.title ??
settings?.disconnected_methods?.[ selectedMethod ]?.title ??
selectedMethod
);
};

const getPaymentMethodDescription = ( method ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ const WithdrawTab = ( { vendor }: WithdrawTabProps ) => {
return <WithdrawTabSkeleton />;
}

// If no withdraw method is globally enabled from Dokan settings,
// show a single clear message instead of connected / not connected sections.
const activeMethods = settings?.active_payment_methods || {};
const hasActiveMethods = Object.keys( activeMethods ).length > 0;

if ( ! hasActiveMethods ) {
return (
<Card className="bg-white shadow p-6">
<DokanAlert
label={ __(
'No withdraw method is available. Please enable payment method from settings.',
'dokan-lite'
) }
variant="info"
/>
</Card>
);
}

return (
<Card className="bg-white shadow p-6">
<div>
Expand Down
Loading