Custom payment method for dokan not saving
-
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)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Custom payment method for dokan not saving’ is closed to new replies.