Skip to content

Instantly share code, notes, and snippets.

@alamgircsebd
Last active April 20, 2021 12:09
Show Gist options
  • Save alamgircsebd/0049ac314267abfb6317c93c88667477 to your computer and use it in GitHub Desktop.
Save alamgircsebd/0049ac314267abfb6317c93c88667477 to your computer and use it in GitHub Desktop.
Dokan add new custom withdraw methods
/**
* Dokan add new withdraw method
*
* @param array $methods
*
* @return array $methods
*/
function dokan_add_new_withdraw_method( $methods ) {
$methods['custom'] = [
'title' => __( 'Custom', 'dokan-lite' ),
'callback' => 'dokan_add_new_withdraw_method_settings'
];
return $methods;
}
add_filter( 'dokan_withdraw_methods', 'dokan_add_new_withdraw_method' );
/**
* Dokan add new withdraw method settings
*
* @param array $store_settings
*
* @return void
*/
function dokan_add_new_withdraw_method_settings( $store_settings ) {
global $current_user;
$email = isset( $store_settings['payment']['custom']['email'] ) ? esc_attr( $store_settings['payment']['custom']['email'] ) : $current_user->user_email; ?>
<div class="dokan-form-group">
<div class="dokan-w8">
<div class="dokan-input-group">
<span class="dokan-input-group-addon"><?php esc_html_e( 'E-mail', 'dokan-lite' ); ?></span>
<input value="<?php echo esc_attr( $email ); ?>" name="settings[custom][email]" class="dokan-form-control email" placeholder="[email protected]" type="text">
</div>
</div>
</div>
<?php
}
/**
* Dokan save custom payment method data for vendors
*
* @param int $store_id
* @param array $dokan_settings
*
* @return void
*/
function dokan_save_custom_payment_method( $store_id, $dokan_settings ) {
$post_data = wp_unslash( $_POST );
if ( isset( $post_data['settings']['custom'] ) ) {
$dokan_settings['payment']['custom'] = array(
'email' => sanitize_email( $post_data['settings']['custom']['email'] ),
);
}
update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
}
add_action( 'dokan_store_profile_saved', 'dokan_save_custom_payment_method', 10, 2 );
/**
* Dokan seller active custom withdraw methods
*
* @param array $active_payment_methods
* @param int $vendor_id
*
* @return array $active_payment_methods
*/
function dokan_seller_active_custom_withdraw_methods( $active_payment_methods, $vendor_id ) {
$store_info = dokan_get_store_info($vendor_id);
$custom = isset( $store_info['payment']['custom']['email'] ) && $store_info['payment']['custom']['email'] !== false ? 'custom' : '';
$active_payment_methods[] = $custom;
return $active_payment_methods;
}
add_filter( 'dokan_get_seller_active_withdraw_methods', 'dokan_seller_active_custom_withdraw_methods', 10, 2 );
/**
* Dokan admin add custom withdraw method details
*
* @return void
*/
function dokan_admin_withdraw_list_add_custom_method() {
?>
<script>
var hooks;
function getCustomPaymentDetails( details, method, data ) {
if (data[method] !== undefined) {
if ('custom' === method) {
details = data[method].email || '';
}
}
return details;
}
dokan.hooks.addFilter( 'dokan_get_payment_details', 'getCustomPaymentDetails', getCustomPaymentDetails, 33, 3 );
</script>
<?php
}
add_action( 'admin_print_footer_scripts', 'dokan_admin_withdraw_list_add_custom_method', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment