首页 > 解决方案 > Dokan pro 插件:添加自定义提款选项但数据不保存

问题描述

我正在为我的供应商制作自定义提款选项。我在下面有以下代码。输入电话号码就可以了。但是,如果我输入一个数字,它不会保存。即使供应商提出提款请求,我也无法从管理员方面看到。

任何帮助表示赞赏。示例:我为供应商提款添加了这种自定义付款方式。然后我以供应商身份登录并通过电话号码更新我的付款方式。

但是数字或任何输入都没有保存。单击保存按钮后它丢失了。

甚至我可以从管理员端提款页面看到电话号码。详细信息 col 为空。

我希望这很清楚。

/**
 * 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;
}```

标签: wordpressdokan

解决方案


推荐阅读