WooCommerce 在 dokan 供应商仪表板中保存自定义值字段

问题描述

受此帖子 (Integrate custom checkboxes in dokan for Woocommerce product) 和 Github 上的 this code 启发,我想将自定义添加的字段和复选框中的值和输入保存到供应商。

我在保存过程中挣扎。我想保存如果复选框“reg_vacation_mode”是否被选中,如果是,则存储所选的假期模式值“immediately_vacation”或“date_wise_vacation”。选择“date_wise_vacation”时,还保存“start_vacation_date”和“end_vacation_date”也。

然后将这些值作为该站点上的列表输出

  • 假期状态:
  • 假期模式:
  • 假期开始:
  • 假期结束:

任何建议如何做到这一点?

// display tab and field in Dokan vendor dashboard
// Adding Settings extra menu in Settings tabs Dahsboard
// -----------------------------------------
add_filter( 'dokan_get_dashboard_nav','dokan_add_settings_menu' );

function dokan_add_settings_menu( $settings_tab ) {
    $settings_tab['vacation'] = array(
        'title' => __( 'Vacation','dokan'),'icon'  => '<i class="fa fa-plane"></i>','url'   => dokan_get_navigation_url( 'settings/vacation' ),'pos'   => 32
    );

    return $settings_tab;
}

 
// Adding input field "immediately" and "date wise" (from & to) vacation 
// -----------------------------------------
add_action( 'dokan_render_settings_content','dokan_render_settings_content',10 );

function dokan_render_settings_content( $query_vars ) {
    if ( isset( $query_vars['settings'] ) && $query_vars['settings'] == 'vacation' ) {
        ?>

        <input type="checkBox" id="reg_vacation_mode" name="_vendor_vacation_mode" value="vacation_mode">
        <label for="vacation_mode">Abwesenheitsmodus aktivieren?</label>
        
            <div class="reveal-if-active">
                <span>Select your vacation mode</span>
            </div>

            <div class="reveal-if-active">
              <input type="radio" id="immediately_vacation" name="drone" value="immediately_vacation" checked>
              <label for="immediately_vacation">Immediately</label>
            </div>

            <div class="reveal-if-active">
              <input type="radio" id="date_wise_vacation" name="drone" value="date">
              <label for="date">Date wise</label>
            
                <div class="reveal-if-active">  
                <label for="start">Start date:</label>
                <input type="date" id="start_vacation_date" name="vacation-start" required>
                    
                <label for="end">End date:</label>
                <input type="date" id="end_vacation_date" name="vacation-end" required>
                </div>
            </div>

        <?PHP
    }

}


// CheckBox for save "_vendor_vacation_mode" status value "inactive" (default) or "active"
// -----------------------------------------
    // Save Vacation status info (inactive,active)
    // Save Vacation type (immediately OR date wise)
    // Save when "date wise" is selected the vacation start & end date
    
        // Saving process
function save_dokan_product_custom_vacation_fields( $product_id,$postdata = null ){
    if ( ! dokan_is_user_seller( get_current_user_id() ) ) {
        return;
    }

    $settings   = get_work_option_field_settings(); // Load field settings
    $field_id   = $settings['reg_vacation_mode']; // Get custom field Metakey
    $Meta_value = array(); // Initializing

    // Loop  through field option settings
    foreach ( $settings['fields'] as $key => $label ) {
        if ( ! empty( $postdata[$field_id.$key] ) ) {
            // add each selected option to the array
            $Meta_value[] = esc_attr( $postdata[$field_id.$key] ); 
        }
    }

    update_post_Meta( $product_id,$field_key,$Meta_value ); // Save
}

        // Output: vendor Vacation Mode: <value>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)