• Resolved diganto24

    (@diganto24)


    I am trying to make a custom withdrawal option but I am failed to save the information and retrieved from admin side.

    My code works fine to make an extra withdrawal option. When I enter phone number from vendor side the number does not saved. I checked from withdrawal option in admin side but details is blank.

    Any help is appreciated.

    add_filter( 'dokan_withdraw_methods', 'add_custom_withdraw_methods' );
    /**
     * Get default to withdrawing methods
     *
     * @return array
     */
    function add_custom_withdraw_methods( $methods ){
    	$methods['payment_gateway_id'] = array(
    		'title'    =>  __( 'Payment Gateway Name', 'dokan-lite' ),
    		'callback' => 'dokan_withdraw_method_dagpay'
    	);
    
    	return $methods;
    }
    /**
     * Callback for Skrill in store settings
     *
     * @global WP_User $current_user
     * @param array $store_settings
     */
    function dokan_withdraw_method_dagpay( $store_settings ) {
    	global $current_user;
    
    	$phone = isset( $store_settings['payment']['payment_gateway_id']['phone'] ) ? esc_attr( $store_settings['payment']['payment_gateway_id']['phone'] ) : '' ;
    	?>
    	<div class="dokan-form-group">
    		<div class="dokan-w8">
    			<div class="dokan-input-group">
    				<span class="dokan-input-group-addon"><?php esc_html_e( 'Phone Number', 'dokan-lite' ); ?></span>
    				<input value="<?php echo esc_attr( $phone ); ?>" name="settings[payment_gateway_id][phone]" class="dokan-form-control phone" placeholder="+0194397933243" type="text">
    			</div>
    		</div>
    	</div>
    	<?php
    }
    
    add_action( 'dokan_store_profile_saved', 'save_withdraw_method_dagpay', 10, 2 );
    /**
     * Save store settings
     *
     * @return void
     */
    function save_withdraw_method_dagpay( $store_id, $dokan_settings ){
    	$existing_dokan_settings = get_user_meta( $store_id, 'dokan_profile_settings', true );
    	$prev_dokan_settings     = ! empty( $existing_dokan_settings ) ? $existing_dokan_settings : array();
    	$post_data               = wp_unslash( $_POST );
    	if( wp_verify_nonce( $post_data['_wpnonce'], 'dokan_payment_settings_nonce' ) ){
    		if ( isset( $post_data['settings']['payment_gateway_id'] ) ) {
    			$dokan_settings['payment']['payment_gateway_id'] = array(
    				'phone' => $post_data['settings']['payment_gateway_id']['phone'], // validate phone number here
    			);
    		}
    	}
    	$dokan_settings = array_merge( $prev_dokan_settings, $dokan_settings );
    
    	update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
    }
    
    add_filter( 'dokan_get_seller_active_withdraw_methods', 'active_payment_methods' );
    /**
     * Get active withdraw methods for the seller.
     * @return array
     */
    function active_payment_methods( $active_payment_methods ){
    	$payment_methods = get_user_meta( dokan_get_current_user_id(), 'dokan_profile_settings' );
    	$payment_gateway = isset( $payment_methods[0]['payment']['payment_gateway_id']['phone'] ) && $payment_methods[0]['payment']['payment_gateway_id']['phone']  !== '' ? 'payment_gateway_id' : '';
    	if( $payment_gateway !== '' ){
    		array_push( $active_payment_methods, 'payment_gateway_id' );
    	}
    
    	return $active_payment_methods;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Jahidul Hassan Mojumder

    (@jahidulhassan)

    Hi @diganto24

    This is not a default feature to add a custom payment method with Dokan. But as you have an understanding of custom code please have a look at https://tanjirsdev.com/add-a-new-payment-gateway-field/ this third-party blog. I hope it my help you to achieve your goal to add a custom payment method in Dokan.

    Let us know if my assistance can be helpful further.

    Thread Starter diganto24

    (@diganto24)

    Thank you, i have copied your exact code and post all code to my function one by one. i am using code snippet plugin to do this. now i am getting everything but data not saved till now. and admin side i can see details is still empty in withdrawal page. confused? can you please give me a code following this.

    Payment method: Mobile Money
    Input type: Number

    Thank you.

    Thread Starter diganto24

    (@diganto24)

    Sorry your code work fine to save an email address. but i need setup as number. if change DIV form control with email>number it stop working. even i wanted change gateway name. if i do so it stop working.

    <input value=”<?php echo esc_attr( $email ); ?>” name=”settings[custom][email]” class=”dokan-form-control email” placeholder=”you@domain.com” type=”number”>

    class=”dokan-form-control email” >if i change this email it does not save anymore. so what to do setup type as number?

    • This reply was modified 2 years, 9 months ago by diganto24.
    Plugin Support Jahidul Hassan Mojumder

    (@jahidulhassan)

    Hi @diganto24

    The save function that was declared in that third-party code snippet was sanitizing the input field’s data if it was an email or not. I am referring to

    $dokan_settings['payment']['custom'] = array(
              'email' => sanitize_email( $post_data['settings']['custom']['email'] ),
          );

    This part of that code. Just replace that part of the code with the below-mentioned snippet and I believe everything will work just fine.

    $dokan_settings['payment']['custom'] = array(
              'email' => esc_html( $post_data['settings']['custom']['email'] ),
          );

    Do let me know if it worked for you.

    Thread Starter diganto24

    (@diganto24)

    Thank you very much. It work fine now. It is that what I am looking for since last 5 days. I appreciate your perfect support for plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom payment method for dokan not saving’ is closed to new replies.